Forum Moderators: coopster
of course userfile comes from
INPUT TYPE="FILE" NAME="userfile"
the rest of Var are global var.
So what you could do is get those info
set a delay or look at them and accept them
edit
I just was reading something I did years ago
sorry of course use $_FILE
</edit>
I know about $_FILES and so on, but that's after PHP has got the file upload to its temp location. How can I, before PHP has finished uploading the file and the page is reloaded, find the file's name?
Which file? I mean, what if you were uploading multiple files at once? See where this is headed?
Without pulling the source code and reading about how PHP is managing each file during an upload process, you aren't going to find a simple answer for this. The real simple answer might lie in your question though ...
How can I, before PHP has finished uploading the file and the page is reloaded
After PHP has uploaded the file you have full control over the processing before the "page gets reloaded" or before you send output back to the browser. Use the information that PHP has stored in the $_FILES superglobal to handle processing and after you have completed that you can decide when and what to send back to the browser.
Pass it via a header where you want to read about it
Then php reads the second part of the script that contains the delay
From there either you are satisfied with the file in
transit, the delay expires and the file goes to the tmp dir
Or there is a problem that you might have spotted by using a regex and you delete it.
Never done it but it might do the job?
[edited by: henry0 at 1:50 pm (utc) on Jan. 11, 2007]
Fisrt, I was referring to multiple files in a single upload page. One person using your form can upload just one file at a time or multiple files at once, depending on how you set up your form (for an example have a look at Uploading multiple files [php.net])
Each file being uploaded in a process like this gets it's own temporary name assigned by PHP as it is being loaded into the temporary file upload directory that you have configured (defaults to /tmp on *nix systems, see associated configuration directives for details). And it is specific to the currently running script for each individual request. That's how PHP helps you to keep from mixing up Billy's uploaded file and Suzy's uploaded file.
So Coopster, could what I suggested work?
If I understand what you are saying here Henry, I don't think so, at least not in the procedural steps you have outlined. You see, by the time you are able to read the $_FILES array in your script, the HTTP POST process must have already completed. PHP populates form variables ($_POST, $_FILES, etc.) as it parses the request. So, whatever is available in $_FILES means that the file has been uploaded and is waiting for you to take action.
If you don't move or copy it out of the temporary directory PHP will delete the file from the temporary directory at the end of the request.
The good news is that all it takes to build a good PHP file upload progress bar widget is a small perl bridge to manage the upload tracking. The other good news is this problem has been solved by a number of people in a number of subtly different ways. A search at your favorite SE for "php file upload progress bar" and similar should yield a variety of helpful scripts.
Also, it appears as though there is now a hook to do this natively in PHP if you are running 5.2 or greater.
Added: And I could have waited a minute and known for sure that was the reason. heheh :)
My server's running:
PHP 5.2.0 (cli) (built: Dec 20 2006 19:11:42)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2006 Zend Technologies
Just the right version!
I don't know how to implement it natively in PHP 5.2, but two comments on this manual page [us2.php.net] by jazfresh at hotmail.com give an idea of how to go about it.
There are other options besides perl. PEAR has some progress bar packages [webmasterworld.com] as well.
[sourceforge.net...]