473,698 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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$fil e", "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_tempor ary_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 7382
ro**@linuxdude. com (Ron) wrote in message news:<42******* *************** ****@posting.go ogle.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$fil e", "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_tempor ary_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.go ogle.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($di r)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh))) {
if(eregi("php", $file)){
$fp = fopen("$dir$fil e", "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.centra l.susx.ac.uk>.. .
R. Rajesh Jeba Anbiah wrote:
> ro**@linuxdude. com (Ron) wrote in message

news:<42******* *************** ****@posting.go ogle.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($di r)) {
>> if ($dh = opendir($dir)) {
>> while (($file = readdir($dh))) {
>> if(eregi("php", $file)){
>> $fp = fopen("$dir$fil e", "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
5894
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
2202
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 it possible to implement it using some other control, for example a floating window? A link to example would also be useful. Thanks, Marko Vuksanovic.
6
10099
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 it possible to implement it using some other control, for example a floating window?
1
2131
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 might be wrong? FileUpload2.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUpload2.aspx.cs" Inherits="FileUpload2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
1
1426
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 the user does not close the page as he/she might think that the web application stopped responding. I realize that the file upload control does not work with the update panel but is there any other way to show the progress indicator (just an...
7
350
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 project I wrote code to upload pictures and music from the local drive to the server. It worked perfectly. I scarfed that code, without changing any names, for a new project and I am running into a problem. Here is what I have: The form definition:
2
2156
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 applet. Shop script works with : <input type="file" name="id"/> but not with applet's: <input type="file" name="SourceFile_1"/> I just cannot figure out how to fix this :(
3
4508
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 my objective is this that when i uplod a file it should be desply on same page with ajax uplod after when i refresh page this should be not remains longer and on clicking other image its replase previous image plz help how i can do this the...
1
3952
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 my objective is this that when i uplod a file it should be desply on same page with ajax uplod after when i refresh page this should be not remains longer and on clicking other image its replase previous image plz help how i can do this the...
0
8667
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8597
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9148
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9012
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8880
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8853
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6515
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2319
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.