Page 1 of 1

Checking filesize

Posted: Tue Nov 14, 2006 6:09 pm
by cnapsys
Hi guys,
I'm having trouble building this script.
I'm trying to check the file size of the temp file multiple times.
Here's what I've tried so far:

Code: Select all

if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path))
	{
	for($i=0; $i<=10; $i++)
		{
		$cksize = filesize($_FILES['userfile']['tmp_name']);
		echo '<br>'.$cksize;
                                }
		echo "<br>The file has been uploaded";
	}
the output tells me that the file has already been moved and it can't get the filesize().
I'm not even sure this can be done. Maybe I didn't understand the way move_uploaded_files() works.
If I can get multiple values of the file size while uploading I could do some nifty little things ;)

Thanks for the tip on including the

Code: Select all

code.

Posted: Tue Nov 14, 2006 6:12 pm
by feyd
The file has finished uploading by the time the script is called. move_uploaded_file() moves the file. If you try to get the filesize of the original location, it will fail if you've already moved the file.

$_FILES['foo']['size'] contains the file size, just so you know.

Posted: Tue Nov 14, 2006 6:15 pm
by cnapsys
Hi feyd,
yeah I know how to get the initial filesize().
What I'm trying to do is get several values of the filesize of the file that is being written.

Posted: Tue Nov 14, 2006 6:24 pm
by feyd
Being written my move_uploaded_file()? I'm pretty sure it is done before you get control back from the function.

Posted: Tue Nov 14, 2006 6:51 pm
by cnapsys
would there be another way (maybe using a different function)??? to get those intermediate values????

Posted: Tue Nov 14, 2006 7:00 pm
by feyd
Unless you write the file yourself, which won't work on safe_mode enabled servers, no.

Posted: Tue Nov 14, 2006 8:26 pm
by Ambush Commander
I think you're trying to build an upload progress bar: http://www.google.com/search?q=php%20upload%20progress

Posted: Tue Nov 14, 2006 8:51 pm
by cnapsys
Ambush Commander wrote:I think you're trying to build an upload progress bar: http://www.google.com/search?q=php%20upload%20progress
I think you're right :D
however, I was trying to do it somewhat different from what's out there.
At this point anything would be helpful.
iframes/javascript/ anything :)

I give up :(

Posted: Tue Nov 14, 2006 9:28 pm
by feyd
The way you're trying to do it, the file has already finished uploading in its entirety.

Posted: Tue Nov 14, 2006 9:47 pm
by cnapsys
feyd wrote:The way you're trying to do it, the file has already finished uploading in its entirety.
trust me feyd. I got that from your first reply regarding the move_uploaded_file :)
I was just trying some work arounds and then I tried the curent progress meters found on google, but I'm not happy with any of 'em.
It looks like 5.2 may have a nifty little feature based on YUI: http://progphp.com/progress.phps
however we can't consider upgrading the php vs on the production server at this point just for this feature.
I'm still on the look out for a work around with iframes.

thanks for your help guys anyway

Posted: Wed Nov 15, 2006 3:24 am
by volka
cnapsys wrote:It looks like 5.2 may have a nifty little feature based on YUI: http://progphp.com/progress.phps
please excuse my blindness but what is the nifty 5.2 feature there?

Posted: Wed Nov 15, 2006 4:07 am
by dibyendrah
move_uploaded_file() returns the control only after whole file is being moved and PHP don't have that feaure which allows us to display progress bar while file is being uploaded.

Posted: Wed Nov 15, 2006 9:58 am
by cnapsys
volka wrote:
cnapsys wrote:It looks like 5.2 may have a nifty little feature based on YUI: http://progphp.com/progress.phps
please excuse my blindness but what is the nifty 5.2 feature there?
the nifty little feature in 5.2 is:
php_rfc1867_callback

From Zend Mailing lists:
"php_rfc1867_callback - a callback function called on the following events:
- MULTIPART_EVENT_START
- MULTIPART_EVENT_FORMDATA
- MULTIPART_EVENT_FILE
- MULTIPART_EVENT_UPDATE
- MULTIPART_EVENT_END"

the link I posted is to an example by Rasmus Lerdorf:
http://progphp.com/progress.php

the 's' at the end of the link takes you to the source page.

It seems that you need to have 'apc.rfc1867 = on' in php.ini for this to work.

Posted: Wed Nov 15, 2006 3:35 pm
by Ambush Commander
Mentioned here too: viewtopic.php?t=58234

But unless you're going to do some PHP extension hacking it's not much use.