Ajax upload not working codeigniter

Another approach to this would be passing to PHP the file encoded in base64:

  • get the selected file from #userfile field using $('#userfile').prop('files')[0];
  • transform the contents of that file into a base64 encoded string using FileReader.readAsDataURL(). We’re going to call this content; Here’s a similar question showing how to do and expanding the answer & possibilities;
  • send the AJAX passing both the filename and content strings;
  • now on CI, fetch the POST data;
  • base64_decode() the content;
  • fwrite() the result into a file using the filename.

That way also you could avoid POSTing all form fields.

Leave a Comment