1

I'm trying to upload a screenshot with a file input and an ajax request. This is my request code:

  var formData= new FormData();
  formData.append('pictureFile', fileInput.files[0]);
  $.ajax({
                       url: 'data/Upload.php',
                       type: 'POST',
                       processData: false,
                       contentType: false,
                       data: formData,
                       success: function (result) {
                           console.log(result);
                       }
                   });

My php code:

$fileName = $_FILES['pictureFile']['tmp_name'];

echo $fileName;

move_uploaded_file($fileName,"dirname");

The upload doesn't seem to be working however, the echo shows me this:

/data/sites/web/hostname/tmp/phplywZbl

When I check this directory right after making the request, it's empty!

I checked the php.ini file and file uploads are definitely on (max size = 2M, screenshot is 25kb).

Does anyone know what's wrong?

user265889
  • 667
  • 1
  • 10
  • 24
  • 1
    This seems like a permissions issue. You'll need to check the write / ownership of the folder. – Adam Oct 16 '17 at 18:16
  • See [How do I get PHP errors to display?](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) to see how to enable output of warning messages that should help with diagnosis – NineBerry Oct 16 '17 at 18:19
  • When you echo something back to the client, the script stops executing. Don't echo until the upload is complete – Walker Boh Oct 16 '17 at 18:20
  • The file is non-existent when you check because its just there for the length of that instance, so its only accessible during the POST request. Then it destroys itself. – Jeff Beagley Oct 16 '17 at 18:51

0 Answers0