Welcome Guest, Not a member yet? Register   Sign In
file upload + jquery
#1

[eluser]ibnclaudius[/eluser]
I'm trying to upload an image using jquery, but always getting the "echo 'fail';".

I'm also using JQuery Ajax Form plugin: http://jquery.malsup.com/form/

My code:

Code:
<form id="new-update-attach-image-form" method="post" action="<?php echo site_url(); ?>/form/upload_school_update_image" enctype="multipart/form-data">
   <input type="file" class="new-update-attach-image-box" accept="image/*">
  </form>

Code:
public function upload_school_update_image()
{
  $config['upload_path'] = './assets/img/school_updates/';
  $config['allowed_types'] = 'gif|jpg|png';
  
  $this->load->library('upload', $config);
  
  if ($this->upload->do_upload())
  {
   echo 'success';
  }
  else
  {
   echo 'fail';
  }
}

Code:
newUpdateAttachImageOptionsUploadBox.change(function ()
{
  newUpdateAttachImageItemName.html(newUpdateAttachImageOptionsUploadBox.val().split('\\').pop());
  newUpdateAttachImageItem.show();
  newUpdateAttachImageOptions.hide();
  
  newUpdateAttachImageForm.ajaxForm(
  {
   target: streamUpdates
  }).submit();
});

#2

[eluser]CroNiX[/eluser]
instead of just echoing 'fail', how about echoing the error(s)?
Code:
echo $this->upload->display_errors();
#3

[eluser]ibnclaudius[/eluser]
Quote:You did not select a file to upload.
#4

[eluser]CroNiX[/eluser]
Try giving your file element a 'name' attribute.
#5

[eluser]ibnclaudius[/eluser]
Thanks, that worked!
#6

[eluser]ibnclaudius[/eluser]
I'm trying to get the file name, but no success

Code:
echo $this->upload->data('file_name')
#7

[eluser]CroNiX[/eluser]
upload->data() returns an array
#8

[eluser]ibnclaudius[/eluser]
How I get a ke tisnide of it?
Should echo $this->upload->data('file_name') not work?
#9

[eluser]CroNiX[/eluser]
Code:
$file_data = $this->upload->data();
echo $file_data['file_name'];




Theme © iAndrew 2016 - Forum software by © MyBB