Necuima Posted April 6, 2013 Share Posted April 6, 2013 Hi Larry, I regularly use the move_uploaded_file function as described in chapter 11 of the book. However the other day I wanted to use it in a form the data of which gets processed via a JQuery AJAX POST call. The form enables the user to select a file for uploading and I was wanting the AJAX-called PHP script to then process it including the move-uploaded_file logic. But it seems that the $_FILES super global values are not visible to the AJAX-called PHP script. Does this sound right? FYI the $_FILES data are visible if I use your technique where the form script calls itself with an 'is submitted' check. (Page 91....). Your insights will be appreciated. Thanks, and Cheers from Oz. Link to comment Share on other sites More sharing options...
HartleySan Posted April 6, 2013 Share Posted April 6, 2013 Necuima, your observations are right on the money. You cannot use Ajax to upload files (well, you can, but not like you think). The following Stack Overflow question/answers should be exactly what you're looking for: http://stackoverflow.com/questions/2320069/jquery-ajax-file-upload Basically, you either need to use an iframe hack, which is supported in all browsers, or you need to use the new HTML5 XHR2 FormData object, which is unfortunately not supported in IE9 and below (as can be readily seen from the following link): http://caniuse.com/xhr2 1 Link to comment Share on other sites More sharing options...
Necuima Posted April 7, 2013 Author Share Posted April 7, 2013 Hi HartleySan, Many thanks for this information. In this particular program, I will use Larry's PHP REDUX approach (pp 91 and onwards) instead of the AJAX approach. Cheers from Oz. Link to comment Share on other sites More sharing options...
Recommended Posts