...

View Full Version : output control function here?



chump2877
07-08-2005, 04:00 AM
Hi,

I have a HTML form:


<form method="post" enctype="multipart/form-data" action="xxxxxxxxx.php">

<input type="hidden" name="MAX_FILE_SIZE" value="2000000">

<br>
<table border="0" cellpadding="0" width="100%">
<tr>
<td align="right" width="45%"><input type="file" name="upload[1]"></td>
<td width="10%"></td>
<td align="left" width="45%"><input type="file" name="upload[2]"></td>
</tr>
<tr>
<td align="right" width="45%"><input type="file" name="upload[3]"></td>
<td width="10%"></td>
<td align="left" width="45%"><input type="file" name="upload[4]"></td>
</tr>
<tr>
<td align="right" width="45%"><input type="file" name="upload[5]"></td>
<td width="10%"></td>
<td align="left" width="45%"><input type="file" name="upload[6]"></td>
</tr>
<tr>
<td align="right" width="45%"><input type="file" name="upload[7]"></td>
<td width="10%"></td>
<td align="left" width="45%"><input type="file" name="upload[8]"></td>
</tr>
<tr>
<td align="right" width="45%"><input type="file" name="upload[9]"></td>
<td width="10%"></td>
<td align="left" width="45%"><input type="file" name="upload[10]"></td>
</tr>
<tr>
<td align="right" width="45%"><input type="file" name="upload[11]"></td>
<td width="10%"></td>
<td align="left" width="45%"><input type="file" name="upload[12]"></td>
</tr>
</table>

<br><br><center><input type="submit" value="Submit"><input type="reset" value="Clear Form"></center>
<br><br>


<input type="hidden" name="mail_to" value="xxxxx@xxxxxxxxxx.com">
<input type="hidden" name="subject" value="File Transfer Confirmation">
<input type="hidden" name="receipt" value="xxxxxx.shtml">



</form>


that I'm using to upload files to a server...When one or more files are selected and then submitted (to be uploaded), a PHP script/file takes over and handles the upload of the files to the server...

What i want to do is, for larger files, add a little animated message that says the files are still transferring....So I whipped out ImageReady and made myself an animated .gif.....

My idea is, when the form is submitted, the user is whisked away to the PHP page that will process the upload...and while that script is transferring the files, I want to force the browser to display my animated .gif with the following code (currently placed at the beginning of the PHP page, before the upload processing code):


if (empty($_FILES['upload']['name'][1]) && empty($_FILES['upload']['name'][2]) && empty($_FILES['upload']['name'][3]) && empty($_FILES['upload']['name'][4]) && empty($_FILES['upload']['name'][5]) && empty($_FILES['upload']['name'][6]) && empty($_FILES['upload']['name'][7]) && empty($_FILES['upload']['name'][8]) && empty($_FILES['upload']['name'][9]) && empty($_FILES['upload']['name'][10]) && empty($_FILES['upload']['name'][11]) && empty($_FILES['upload']['name'][12]))
{
$v = $v;
}
else
{
print '<br<br><center><img src="transfer_animation.gif"></center>';
}


The problem I'm having is that, when the submit button is pressed on the HTML form, the browser never advances to the PHP page and displays my animation....it stays at the HTML form page, the mouse pointer turns to the hour glass, and the status bar of the browser indicates that it's working on something (obviously, it must be uploading, becasue these pages DO work like they're supposed to)....

The funny thing is that the animation code appears BEFORE the upload processing code on the PHP page...So I just assumed that the animation would output to the browser BEFORE the upload processing code kicked in...

How do I force the page to advance to my PHP page and display my animated .gif ??....I'm wondering if this could be acheived with a PHP output control function on the PHP page, to keep the upload processing code from kicking in until after the animation is outputted to the browser, but I'm not sure....

Can someone help?

Thanks.

Fou-Lu
07-08-2005, 09:16 AM
Perhaps output control (http://ca3.php.net/manual/en/ref.outcontrol.php) will suffice for what you are looking for?
ex:



ob_start();
echo '<img src="yourimage.gif" />'; // And whatever else you want to use

ob_end_flush();

// Continue with your processing code, perhaps adjust after or provide a message displaying upload completed.

Didn't test this or anything of the sorts, and I'm not really the king of output buffering, but this will probably work for you.

chump2877
07-09-2005, 03:04 AM
I tried the code that you provided, and it still didn't force the browser to advance to the next page and output the animation....

I even tried this code:


if (empty($_FILES['upload']['name'][1]) && empty($_FILES['upload']['name'][2]) && empty($_FILES['upload']['name'][3]) && empty($_FILES['upload']['name'][4]) && empty($_FILES['upload']['name'][5]) && empty($_FILES['upload']['name'][6]) && empty($_FILES['upload']['name'][7]) && empty($_FILES['upload']['name'][8]) && empty($_FILES['upload']['name'][9]) && empty($_FILES['upload']['name'][10]) && empty($_FILES['upload']['name'][11]) && empty($_FILES['upload']['name'][12]))
{
$v = $v;
}
else
{
print '<br><br><center><img src="transfer_animation.gif"></center>';

}


print '<br><br><center><img src="transfer_animation.gif"></center>';
die();

on the off chance that the IF statement was getting skipped over....The result? The same as before!!! Using die() still didn't force the script to exit and output anything to the browser thus far!

Very strange. Any thoughts?

Thanks.


Edit: Maybe I need to apply the output buffer controls to the chunk of code that processes the file uploads, instead? In other words, force that chunk of code to NOT run until everything else in the script has run its course.....How would that work?

chump2877
07-09-2005, 04:43 AM
Argh, I can't figure this out...it seems that whatever I do, the upload processing code HAS TO go first....It's to the extent that if I insert a die() in the code somewhere, the file upload is processed first BEFORE die() tells the script to end...even if die() is placed BEFORE the upload processing code...

It's almost like if you call on a $_FILES variable ANYWHERE in the script, this takes precedence over anything else in the code, and must be evaluated first...or something like that

Grrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.... :mad:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum