PHP: Problem with filesize
I need a little help here:
I get a file from an HTML upload form. And I have a "target" filename in $File.
When I do this:
copy($_FILES['binfile']['tmp_name'], $File);
echo '<hr>' . filesize($_FILES['binfile']['tmp_name']);
echo '<hr>' . filesize($File);
Everything works fine. I get the same number twice.
However when I delete the first call of filesize(), I get "0" (zero).
copy($_FILES['binfile']['tmp_name'], $File);
echo '<hr>' . filesize($File);
Any suggestions? What am I doing wrong? Why do I need to get the filesize of the "original" file before I can get the size of the copy?
(That's actually what it is: I need to call the filesize() for the original file. Neither sleep() n开发者_Go百科or calling filesize() of another file helps.)
System:
- Apache 2.0
- PHP 5.2.6
- Debian Linux (Lenny)
How big is this file? You are doing a copy and then stating the file straight away. Could this be the problem?
Does the builtin move_uploaded_file() function give the same behavior?
Try this:
copy($_FILES['binfile']['tmp_name'], $File);
clearstatcache();
$filesize = $_FILES['binfile']['size'];
echo '<hr>' . $filesize;
How about this:
copy($_FILES['binfile']['tmp_name'], $File);
clearstatcache();
while (empty(filesize($File)))
sleep(2);
echo '<hr>' . filesize($File);
OR try this:
copy($_FILES['binfile']['tmp_name'], $File);
clearstatcache();
while (!file_exists($File))
sleep(2);
echo '<hr>' . filesize($File);
精彩评论