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
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
Comment