Jump to content

Recommended Posts

Hello all.

 

I was looking at the way PHP handles file uploads.

It seems that PHP uses a temporarily directory and file name for file uploads.

e.g. /var/www/virtual/SITE/phptmp/phpMhOniL

 

This file is deleted/moved straight after the upload finished.

Now I was wondering what this file looks like, so I decided to log on with filezilla, navigate to that dir, upload a HUGE file with php (takes a lot of time), and then refresh the directory listing in filezilla.

 

To my suprise: No file to be found... (exept for some sessions)

 

How is this possible?

How can the move_uploaded_file function work, while I cant find the file?

 

I hope someone can help me out.

Link to comment
https://forums.phpfreaks.com/topic/184286-keeping-track-of-php-uploads/
Share on other sites

I take it that you are looking at the tmp directory of PHP through filezilla, if so, the reason you cannot see the file is it is being moved and or deleted after the script is done processing. PHP only stores the file temporarily for the duration of the script life or until it is moved. Once the script ends, if the file was not moved it is deleted.

"PHP only stores the file temporarily for the duration of the script life or until it is moved."

Euhm, thats the problem. I am uploading 160mb, takes 10min for me, and still NO temp php file (php exec limit is high enough).

(I am looking with filezilla at the temp directory WHILE i am uploading)

 

How is this possible?

I am not 100% how PHP does handle file uploads and why you cannot view them, but you can put a sleep function before you move the file, say a 60 second sleep (be sure to set the set_time_limit to 90 so the script does not time out. Using this method you can upload a very small file and you should be able to see it. within those 60 seconds.

 

It could possibly be that the file is created as a "hidden" file and the FTP does not show those, I do not know. But try the above and see if you can see it then. Alternatively, you can look at the PHP Manual for Handling POST Uploads if you have not already to find out more information.

I did what you said, and guess what.

 

The php uploading process goes as follows:

1. Client uploads file

2. When php received the FULL file (all bytes) it creates the temp file

3. Move_uploaded_file() moves that file almost a split second later

4. The temp file is deleted if move failed

 

So now I have a new question.

Where is the file between step 1-2

Where is the REAL php temp dir which is used during uploads.

Or does it store the file in its memory or so?

 

It's the web server that processes the file while it is being uploaded. The web server only invokes the .php file that is the target of the upload once the request has been received (i.e. the whole file has been uploaded.)

 

It's likely the size of the file you are trying is small enough that it is being entirely held in the disk cache in memory while the web server is receiving it. You might try a larger file.

 

Why exactly do you need to know this?

Here is some information I just found out by testing under Windows -

 

If the CONTENT_LENGTH header (it's the sum of the size of all files under one form submission) of the file(s) being uploaded is greater than either the post_max_size or upload_max_filesize setting, then the temp file(s) is(are) not written to the temporary directory. When the CONTENT_LENGTH of the file(s) being uploaded is less then both those settings, the files are written to the temp folder as they are being uploaded.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.