PHP file upload and curl PHP file upload and curl curl curl

PHP file upload and curl


Because you are using CURL you are sending the web server a new request.There are a couple of things you are asking the web server to do:

  • get uploaded file
  • process script send
  • new request to web server process
  • second request

in the mean time, the engine knows it needs to perform the following task;tidy up uploaded files

The different environments opens the possibilty to process those tasks in a different order (e.g. Linux+Apache vs Windows+IIS). When it decides to tidy up the uploaded files would explain what you are seeing:

  • get uploaded file
  • process script send
  • new request to web server
  • <- here
  • process second request
  • <- here

in the first position, your script breaks, in the second it will work. This is because in the first spot your uploaded file has been deleted before your second request/script is processed/run. Like Marc mentioned, this is core functionality so you will need to modify your script to use move_uploaded_file() and then pass the location of the file to your other script.

Hopefully that sheds some light on why it's operating differently in the different environments.


You'd have to move the file out of /tmp to another directory using move_uploaded_file() when the original upload finishes, or initiate the curl upload from within the same script. Otherwise PHP will clean up the file and there's not much else you can do.

The automatic cleanup is core PHP functionality, and curl can't affect it.