PHP Classes

upload progress problem

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  Locating addresses on...  >  All threads  >  upload progress problem  >  (Un) Subscribe thread alerts  
Subject:upload progress problem
Summary:upload progress sometimes work, sometimes not
Messages:11
Author:MyVar
Date:2006-12-24 18:04:11
Update:2007-01-02 18:28:28
 
  1 - 10   11 - 11  

  1. upload progress problem   Reply   Report abuse  
Picture of MyVar MyVar - 2006-12-24 18:04:11
Hi,
i use the upload progress plugin on a php5 system. Im confusing because sometimes the script shows the upload progress and sometimes not. If I upload a few files one after another then the progress bar dont appear. For example, I open the browser and upload a file the progress bar appear. After that i close this browser window and open a new one. Now the progress bar dont appears but the file will be uploaded. I test it with the same file, and with different files - always the same problem.

If I wait a few minutes sometimes it works. Has anybody the same problem or any idea how can i fix this?

thx
Mark

  2. Re: upload progress problem   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-12-24 20:08:11 - In reply to message 1 from MyVar
When the file is too small, the upload may finish much faster than the progress monitor can be sent back to the browser.

If you try large files or send the form to a server in a network slower to access, the progress bar always appears after the first few seconds.

  3. Re: upload progress problem   Reply   Report abuse  
Picture of MyVar MyVar - 2006-12-24 22:12:19 - In reply to message 2 from Manuel Lemos
hi manuel,
no i dont think that this is the problem. Have a look this is my test.php upload progress bar. I have tested it with different file sizes.

<?php
/*
* test_upload_progress.php
*
* @(#) $Header: /home/mlemos/cvsroot/forms/test_upload_progress.php,v 1.6 2006/12/21 14:29:51 mlemos Exp $
*
*/

require('forms.php');
require('form_ajax_submit.php');
require('form_upload_progress.php');

$form=new form_class;
$form->NAME='upload_form';
$form->METHOD='POST';
$form->ACTION='';
$form->ENCTYPE='multipart/form-data';
$form->debug='error_log';
$form->ResubmitConfirmMessage=
'Are you sure you want to submit this form again?';
$form->AddInput(array(
'TYPE'=>'file',
'NAME'=>'userfile',
'ValidateAsNotEmpty'=>1,
'ValidationErrorMessage'=>
'It was not specified a valid file to upload'
));
$form->AddInput(array(
'TYPE'=>'submit',
'VALUE'=>'Upload',
'NAME'=>'doit'
));
$form->AddInput(array(
'TYPE'=>'hidden',
'NAME'=>'MAX_FILE_SIZE',
'VALUE'=>9000000
));
$form->AddInput(array(
'TYPE'=>'custom',
'NAME'=>'upload_progress',
'ID'=>'upload_progress',
'FeedbackElement'=>'feedback',
'FeedbackFormat'=>
'<center>
<table style="width: 200px" class="progress_container" border="1">
<tr><td style="width: {ACCURATE_PROGRESS}%;" class="progress_bar">
<tt>{PROGRESS}%</tt></td><td style="border-style: none;"></td>
</tr></table><br />
<tt>Uploaded {UPLOADED}B of {TOTAL}B<br />
Remaining time: {REMAINING}<br />
Average speed: {AVERAGE_SPEED}B/s<br />
Current speed: {CURRENT_SPEED}B/s</tt></center>',
'CustomClass'=>'form_upload_progress_class'
));

/*
* Handle client side events on the server side.
* Do not output anything before these lines.
*/
$form->HandleEvent($processed);
if($processed)
exit;

$form->LoadInputValues($form->WasSubmitted('doit'));
$verify=array();
if($form->WasSubmitted('doit'))
{
sleep(1);
if(($error_message=$form->Validate($verify))=='')
$doit=1;
else
{
$doit=0;
$error_message=HtmlEntities($error_message);
}
}
else
{
$error_message='';
$doit=0;
}
if(!$doit)
{
if(strlen($error_message))
{
Reset($verify);
$focus=Key($verify);
}
else
$focus='userfile';
$form->ConnectFormToInput($focus, 'ONLOAD', 'Focus', array());
}
$onload=HtmlSpecialChars($form->PageLoad());

?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test for Manuel Lemos' PHP form class
to show upload file progress</title>
<style type="text/css"><!--
.progress_container { background-color: #c0c0c0; border-radius: 8px;
-moz-border-radius: 8px; padding: 4px; }
.progress_bar { border-style: none; color: #000000; padding: 4px;
background-color: #0000ff; background-image: url(progress.gif);
text-align: center; }
// --></style>
</head>
<body onload="<?php echo $onload; ?>" bgcolor="#cccccc">
<h1><center>Test for Manuel Lemos' PHP form class
to show upload file progress</center></h1>
<hr />
<img src="progress.gif" width="0" height="0" />
<?php

if($doit)
{
$form->GetFileValues('userfile',$userfile_values);
?>
<h2><center>The file was uploaded.</center></h2>
<center><table>

<tr>
<th align="right">Uploaded file path:</th>
<td><tt><?php echo $userfile_values['tmp_name']; ?></tt></td>
</tr>

<tr>
<th align="right">Client file name:</th>
<td><tt><?php echo HtmlEntities($userfile_values['name']); ?></tt></td>
</tr>

<tr>
<th align="right">File type:</th>
<td><tt><?php echo $userfile_values['type']; ?></tt></td>
</tr>

<tr>
<th align="right">File size:</th>
<td><tt><?php echo $userfile_values['size']; ?></tt></td>
</tr>

</table></center>
<?php
}
else
{
$form->AddInputPart('upload_progress');
$form->AddInputPart('MAX_FILE_SIZE');
$form->StartLayoutCapture();
$title='Form upload progress test - 9MB maximum size';
$body_template='form_upload_body.html.php';
include('templates/form_frame.html.php');
$form->ShowAllErrors=1;
$form->EndLayoutCapture();
$form->DisplayOutput();
}
?>
<hr />
</body>
</html>

  4. Re: upload progress problem   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-12-25 13:06:26 - In reply to message 3 from MyVar
There are other problems that may affect the situation.

There are some browsers that do not show the progress bar at all because they are not able to load the response another parallel request during the upload. Which browser are you using?

I know that Konqueror is one of them. Firefox with SessionSaver extension also seems to exhibit problems because that extension stores the request data in memory.

Are you able to see working the online example that I mentioned in the article?

  5. Re: upload progress problem   Reply   Report abuse  
Picture of MyVar MyVar - 2006-12-25 13:17:26 - In reply to message 4 from Manuel Lemos
hi manuel,
i use the ie7 and i can see the example from you. It works without any problems. Is it possible that the server cache makes any probs?

  6. Re: upload progress problem   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-12-25 14:07:13 - In reply to message 5 from MyVar
I think the problem is just the upload speed. If you upload the file to a server that accepts it very quickly, it will not have the time to start displaying the progress bar.

For instance, when I try it in my local development machine, on which the Web server is also installed, I do not see the progress bar unless I try uploading a file with at least a few hundred megabytes.

  7. Re: upload progress problem   Reply   Report abuse  
Picture of MyVar MyVar - 2006-12-25 20:15:05 - In reply to message 6 from Manuel Lemos
no i dont think so, i can upload a file with 800kb a few times with your script and the progress bar always appears. If i upload the same file on my server it doesn't work. I can upload with 16kb/s. The script runs on a standard server. When I upload the file with my script i have to wait the same time as by your script but by mine the bar doesn't appear. Consequential it couldn't be the upload speed.

its really crazy. This script (http://www.meta-language.net/forms-examples.html?example=test_upload_progress) runs on a patched php4 version or? Perhaps its only a php5 bug? Perhaps it could be a problem with the cache handle of php because sometimes it works, sometimes not.

big thx to you for your help at Christmas

  8. Re: upload progress problem   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-12-26 17:48:08 - In reply to message 7 from MyVar
I have tested it first with PHP 5.2 before I ported the patch to PHP 4. It works well in both versions. I use Apache 1.3.x as Web server and Firefox as browser. I also tested with Internet Explorer 6. Right now, I do not have a Windows version that can be used to test Internet Explorer 7. Maybe there is something different with that browser and whatever Web server do you use.

  9. Re: upload progress problem   Reply   Report abuse  
Picture of MyVar MyVar - 2006-12-27 01:05:02 - In reply to message 8 from Manuel Lemos
the scripts work on php 5.2 and
Apache/1.3.33 (Unix) PHP/5.2.0
Timeouts Connection: 30 - Keep-Alive: 3

this is package is installed too:
pecl.php.net/package/uploadprogress

must i change something in the php.ini?

  10. Re: upload progress problem   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-12-27 01:48:32 - In reply to message 9 from MyVar
Not really, just this line should be sufficient:

extension=uploadprogress.so

I use Apache 1.3.37, but I do not think it changes anything.

What could be interfering may be any security modules, but usually those block file uploads altogether.

What you can do now is to look at the Web server access logs. You should see a POST request and a GET request after the upload is done.

If the GET request appears much sooner than the upload ended, that means that the form upload progress plug-in waited 10 seconds for the upload statistics information but it did not show up.

I remember that I also fixed a bug in the form upload progress plug-in could make it look at the wrong upload identifier. Since you said you were opening a new browser window to submit the new upload form, I don't think that is your case, but you may also try the fixed version getting it from here:

meta-language.net/cvs/~checkout~/fo ...

 
  1 - 10   11 - 11