473,397 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

PHP upload progress indicator and tmp_name

Ron
I spent the last couple of days setting up a progress indicator for a
private site that only does a couple uploads a day. After figuring out
there was no way to set the 'upload_tmp_dir' or 'tmp_name' per
session, I resigned to just doing an opendir() and finding the one
file in 'upload_tmp_dir' since I knew there would never be an issue
with multiple uploads occuring at the same time.

if(is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh))) {
if(eregi("php", $file)){
$fp = fopen("$dir$file", "r");
$fstat = fstat($fp);
echo "Bytes uploaded: " . $fstat[7] . "<br>\n";
fclose($fp);
closedir($dh);
$done = 0;
}
}
}
}

This works ok and I just do a JS popup with a meta refresh to show how
many bytes have been uploaded so far. I'm not concerned with knowing
the actual filesize, only showing that the upload is working and how
fast it's working, as you can see in the code above.

After all this, the question came to mind as to why it would be
difficult or a security problem to prepend or append something like a
timestamp or sid to the tmp_name so that one could reliably figure out
which tmp file they needed to stat? As would be the case with multiple
uploads. I've looked through the PHP source, specifically
php_open_temporary_file.c and don't see what the problem would be, but
then I'm not an expert at C or PHP.

Thanks for any enlightment here.
Ron
Jul 17 '05 #1
4 7352
ro**@linuxdude.com (Ron) wrote in message news:<42**************************@posting.google. com>...
I spent the last couple of days setting up a progress indicator for a
private site that only does a couple uploads a day. After figuring out
there was no way to set the 'upload_tmp_dir' or 'tmp_name' per
session, I resigned to just doing an opendir() and finding the one
file in 'upload_tmp_dir' since I knew there would never be an issue
with multiple uploads occuring at the same time.

if(is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh))) {
if(eregi("php", $file)){
$fp = fopen("$dir$file", "r");
$fstat = fstat($fp);
echo "Bytes uploaded: " . $fstat[7] . "<br>\n";
fclose($fp);
closedir($dh);
$done = 0;
}
}
}
}

This works ok and I just do a JS popup with a meta refresh to show how
many bytes have been uploaded so far. I'm not concerned with knowing
the actual filesize, only showing that the upload is working and how
fast it's working, as you can see in the code above.
This seems to be a very nice hack. Yet, I haven't seen a pure PHP
solution for progress bar. Yet, I haven't tried your solution, but
looks promising. Congrats!
After all this, the question came to mind as to why it would be
difficult or a security problem to prepend or append something like a
timestamp or sid to the tmp_name so that one could reliably figure out
which tmp file they needed to stat? As would be the case with multiple
uploads. I've looked through the PHP source, specifically
php_open_temporary_file.c and don't see what the problem would be, but
then I'm not an expert at C or PHP.


Sorry, no idea.

--
"Success is not what you achieve, but it is what you die for"
If you live in USA, please support John Edwards.
Email: rrjanbiah-at-Y!com
Jul 17 '05 #2
R. Rajesh Jeba Anbiah wrote:
ro**@linuxdude.com (Ron) wrote in message news:<42**************************@posting.google. com>...
I spent the last couple of days setting up a progress indicator for a
private site that only does a couple uploads a day. After figuring out
there was no way to set the 'upload_tmp_dir' or 'tmp_name' per
session, I resigned to just doing an opendir() and finding the one
file in 'upload_tmp_dir' since I knew there would never be an issue
with multiple uploads occuring at the same time.

if(is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh))) {
if(eregi("php", $file)){
$fp = fopen("$dir$file", "r");
$fstat = fstat($fp);
echo "Bytes uploaded: " . $fstat[7] . "<br>\n";
fclose($fp);
closedir($dh);
$done = 0;
}
}
}
}

This works ok and I just do a JS popup with a meta refresh to show how
many bytes have been uploaded so far. I'm not concerned with knowing
the actual filesize, only showing that the upload is working and how
fast it's working, as you can see in the code above.

This seems to be a very nice hack. Yet, I haven't seen a pure PHP
solution for progress bar. Yet, I haven't tried your solution, but
looks promising. Congrats!


There was a patch for the PHP source code that allowed for an upload
meter. You can find information, the patch and demo scripts at:

http://pdoru.from.ro/

Also mentioned in:

http://www.zend.com/zend/week/week140.php
http://www.zend.com/zend/week/week146.php
http://www.zend.com/zend/week/week154.php
http://www.zend.com/zend/week/week161.php

and possibly a few more. :)

I haven't tried the patch, but it does look to be a great solution.

Andy
Jul 17 '05 #3
Andrew Collington <NO*******************@sussex.ac.uk.NOSPAM> wrote in message news:<c1**********@ames.central.susx.ac.uk>...
R. Rajesh Jeba Anbiah wrote:
> ro**@linuxdude.com (Ron) wrote in message

news:<42**************************@posting.google. com>...
>
>>I spent the last couple of days setting up a progress indicator for a
>>private site that only does a couple uploads a day. After figuring out
>>there was no way to set the 'upload_tmp_dir' or 'tmp_name' per
>>session, I resigned to just doing an opendir() and finding the one
>>file in 'upload_tmp_dir' since I knew there would never be an issue
>>with multiple uploads occuring at the same time.
>>
>>if(is_dir($dir)) {
>> if ($dh = opendir($dir)) {
>> while (($file = readdir($dh))) {
>> if(eregi("php", $file)){
>> $fp = fopen("$dir$file", "r");
>> $fstat = fstat($fp);
>> echo "Bytes uploaded: " . $fstat[7] . "<br>\n";
>> fclose($fp);
>> closedir($dh);
>> $done = 0;
>> }
>> }
>> }
>>}
>>
>>This works ok and I just do a JS popup with a meta refresh to show how
>>many bytes have been uploaded so far. I'm not concerned with knowing
>>the actual filesize, only showing that the upload is working and how
>>fast it's working, as you can see in the code above.

>
>
> This seems to be a very nice hack. Yet, I haven't seen a pure PHP
> solution for progress bar. Yet, I haven't tried your solution, but
> looks promising. Congrats!


There was a patch for the PHP source code that allowed for an upload
meter. You can find information, the patch and demo scripts at:

http://pdoru.from.ro/

Also mentioned in:

http://www.zend.com/zend/week/week140.php
http://www.zend.com/zend/week/week146.php
http://www.zend.com/zend/week/week154.php
http://www.zend.com/zend/week/week161.php

and possibly a few more. :)


And the quite famous is <http://www.raditha.com/php/progress.php>
(with bit of Perl) as they claim that can be used without any patch to
PHP.

Ron's solution is very creative and simple.

--
"Success is not what you achieve, but it is what you die for"
If you live in USA, please support John Edwards.
Email: rrjanbiah-at-Y!com
Jul 17 '05 #4
Ron
>
http://pdoru.from.ro/

Also mentioned in:

http://www.zend.com/zend/week/week140.php
http://www.zend.com/zend/week/week146.php
http://www.zend.com/zend/week/week154.php
http://www.zend.com/zend/week/week161.php

and possibly a few more. :)

I haven't tried the patch, but it does look to be a great solution.

Andy


Thanks for the info Andy, and kudos to the author. Looks like it was a
a fair amount of work, and he found and fixed an issue with the
apache2 interface in the process.
Ron

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jim Michaels | last post by:
after a file upload, $_FILES is not populated but $_POST is. what's going on here? $_POST=C $_POST=C $_POST=C $_POST=C:\\www\\jimm\\images\\bg1.jpg $_FILES= $_FILES= $_FILES=
1
by: Marko Vuksanovic | last post by:
I am trying to implement a file upload progress indicator (doesn't have to be a progress bar) using atlas... I do realize that the indicator cannot be implemented using Update panel control, but is...
6
by: Marko Vuksanovic | last post by:
I am trying to implement a file upload progress indicator (doesn't have to be a progress bar) using atlas... I do realize that the indicator cannot be implemented using Update panel control, but is...
1
by: Marko Vuksanovic | last post by:
I used the following code for implementing a file upload progress indicator, using UpdateProgress Panel, though I have a problem that FileUpload.Has File always returns false. Any suggestions what...
1
by: M.V. | last post by:
I'm trying to implement a progress indicator using atlas. Note that this indicator does not have to reflect the real progress but just to let the user know that the something is being done so that...
7
by: Shelly | last post by:
I do what most programmers do -- we steal code from stuff we have written before, or accept code from others that works, before we attempt to write something altogether new. On a previous...
2
by: Event Horizon | last post by:
Hi, I'm trying to add an simple upload applet to shopping cart script. My new applet form sends all needed post fields ( quantity, product, etc... ) but the "file" post field is hardcoded in...
3
by: kksandeep | last post by:
i am using this three files to uplod file. i got this file from net but i think these have some error. i am new to this field plz help the script i found is some helpful but not too that i need ...
1
by: kksandeep | last post by:
i am using this three files to uplod file. i got this file from net but i think these have some error. i am new to this field plz help the script i found is some helpful but not too that i need ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.