Jump to content

Archived

This topic is now archived and is closed to further replies.

facelessface

progress bar...

Recommended Posts

I realise that a progress bar for php isn't possible without using perl etc..

So what I want to do (if possible), is redirecting people to a 'loading please wait' page upon clicking the submit button on the form. Then dealing with the file upload. Then redirecting back to the original page.

Is that possible? If so, how?!

Share this post


Link to post
Share on other sites
Hello,
I do not believe you can do that with php but with ajax,
this is a one file script that'll do it for you :
[a href=\"http://encodable.com/filechucker\" target=\"_blank\"]http://encodable.com/filechucker[/a]

Cheers,
Andi

Share this post


Link to post
Share on other sites
[!--quoteo(post=376820:date=May 24 2006, 04:18 PM:name=facelessface)--][div class=\'quotetop\']QUOTE(facelessface @ May 24 2006, 04:18 PM) [snapback]376820[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I realise that a progress bar for php isn't possible without using perl etc..

So what I want to do (if possible), is redirecting people to a 'loading please wait' page upon clicking the submit button on the form. Then dealing with the file upload. Then redirecting back to the original page.

Is that possible? If so, how?!
[/quote]

it IS possible to do a progress bar with only PHP, no Javascript at all was needed. My friend made one (I still have the code for it). I'll ask him when he logs back on if I can share the code for it heh

Share this post


Link to post
Share on other sites
As far as I know the only option you have is to load a page with an animated gif (or what ever to show something is happening).
The html is output first and then the php script. Once all the php code has finished executing have the last line echo out javascript to close the window.

Its not really a progress bar in the sense that it analyses the percentage of work done - but it looks like one!

Share this post


Link to post
Share on other sites
[!--quoteo(post=376833:date=May 24 2006, 05:48 PM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ May 24 2006, 05:48 PM) [snapback]376833[/snapback][/div][div class=\'quotemain\'][!--quotec--]
As far as I know the only option you have is to load a page with an animated gif (or what ever to show something is happening).
The html is output first and then the php script. Once all the php code has finished executing have the last line echo out javascript to close the window.

Its not really a progress bar in the sense that it analyses the percentage of work done - but it looks like one!
[/quote]

Nope! This script also shows the true upload percentage as it goes :)

Share this post


Link to post
Share on other sites
uh.. i really don't think that's strictly php doing that... i'd be interested in seeing this code too.

and as far as ^^post... putting html first and then php doesn't change anything. the server looks at the file, reads the whole thing, parses the php and then sends the entire thing to the client. putting the html first does not send it first, while the php is parsing.

Share this post


Link to post
Share on other sites
[!--quoteo(post=376891:date=May 24 2006, 11:29 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 24 2006, 11:29 PM) [snapback]376891[/snapback][/div][div class=\'quotemain\'][!--quotec--]
uh.. i really don't think that's strictly php doing that... i'd be interested in seeing this code too.

and as far as ^^post... putting html first and then php doesn't change anything. the server looks at the file, reads the whole thing, parses the php and then sends the entire thing to the client. putting the html first does not send it first, while the php is parsing.
[/quote]

So is there NO way of doing a simple animated gif then?

Mike

Share this post


Link to post
Share on other sites
Not strictly with PHP no. It can however be done with a mixture of HTML, PHP and JavaScript to create an illusion of a progress bar (i.e. the animated gif method), to get a true progress bar with a percentage and maybe even an upload speed, you'd need something like AJAX or asp.net I guess.

Share this post


Link to post
Share on other sites
[!--quoteo(post=376943:date=May 25 2006, 04:42 AM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ May 25 2006, 04:42 AM) [snapback]376943[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Not strictly with PHP no. It can however be done with a mixture of HTML, PHP and JavaScript to create an illusion of a progress bar (i.e. the animated gif method), to get a true progress bar with a percentage and maybe even an upload speed, you'd need something like AJAX or asp.net I guess.
[/quote]

OK - so how would I do it using javascript and php. Sorry for the simple question - but my js skills are pretty limited

Share this post


Link to post
Share on other sites
"to get a true progress bar with a percentage and maybe even an upload speed, you'd need something like AJAX or asp.net I guess."

No you dont, the true process involves basically just php, some frames, and a meta refresh.

Here is the code you would use, it uses FTP to upload the files and report the current percentage..

main.php
[code]
<?php

$link = mysql_connect("***", "***", "***") or die(mysql_error());

//select the database
$db_selected = mysql_select_db("YourDB", $link) or die(mysql_error());

$transactionID = $_GET['id'];

$result = mysql_query("SELECT * FROM ftp WHERE transactionID='$transactionID'");
$row = mysql_fetch_array($result);
if($row)
{

    mysql_query("UPDATE ftp SET percentage='0' WHERE transactionID='$transactionID'") or die(mysql_error());
}
else
{
    mysql_query("INSERT INTO ftp (transactioNID, percentage) VALUES ('$transactionID', '0')") or die(mysql_error());
}

echo("Please wait while your files are uploaded...<br><iframe src=\"upload.php?id={$transactionID}\" frameborder=0 width=1 height=1></iframe><br>
<iframe src=\"progress.php?id={$transactionID}\" frameborder=0 height=100 width=400></iframe>");


?>
[/code]

progress.php
[code]
<?php


$link = mysql_connect("***", "***", "***") or die(mysql_error());

//select the database
$db_selected = mysql_select_db("YourDB", $link) or die(mysql_error());


$transactionID = $_GET['id'];
$result = mysql_query("SELECT * FROM ftp WHERE transactionID='$transactionID'");
$row = mysql_fetch_array($result);
if($row['percentage'] == "-1")
{
    echo("Your file is finished uploading!");
}
else
{
    $other = 100 - $row['percentage'];
    echo("
        <meta http-equiv=\"refresh\" content=\"3\">
        <style type=\"text/css\">
            .borderTable{    
                padding: 2px 4px 2px 4px;
                border: 1px solid black;
            }
        </style>
        <table width='350' border='0' cellpadding='0' cellspacing='0'>
              <tr>
                <td>
                      <table width='100%' class='borderTable' border='0' cellpadding='0' cellspacing='0'>
                        <tr>
                              <td>
                                  <table width='{$row['percentage']}%' border='0' cellpadding='0' cellspacing='0'>
                                    <tr>
                                          <td bgcolor='blue'>&nbsp;</td>
                                    </tr>
                                  </table>
                            </td>
                        </tr>
                      </table>
                </td>
              </tr>
              <tr>
                <td><div align='center'>{$row['percentage']}% Complete</div></td>
              </tr>
        </table>");
}

?>
[/code]

upload.php
[code]
<?php


$link = mysql_connect("***", "***", "***") or die(mysql_error());

//select the database
$db_selected = mysql_select_db("YourDB", $link) or die(mysql_error());

/* FTP Information */
$server = "192.168.0.1";
$login = "FTPUsername";
$password = "FTPPassword";
$file = "FileToUpload.zip";



$conn_id = ftp_connect($server, 21, 30); //times out after 30 seconds if connection not established
if($conn_id)
{
    $login_result = ftp_login($conn_id, $login, $password);
    if($login_result)
    {
        $fp = f open($file, 'r');
        $ret = ftp_nb_fput($conn_id, $file, $fp, FTP_BINARY);
           while ($ret == FTP_MOREDATA)
        {
            $totalbytes = filesize($file); //total number of bytes in the file
              $bytes = ftell($fp); //tells number of bytes uploaded
            $bytes = $bytes*100;
            $percentage = $bytes/$totalbytes;
            $percent = explode(".", $percentage);    
            $transactionID = $_GET['id'];
            $result = mysql_query("SELECT * FROM ftp WHERE transactionID='$transactionID'");
            $row = mysql_fetch_array($result);
            if(!$row)
            {
                mysql_query("INSERT INTO ftp (transactioNID, percentage) VALUES ('$transactionID', '$percent[0]')") or die(mysql_error());
            }
            else
            {
                mysql_query("UPDATE ftp SET percentage='$percent[0]' WHERE transactionID='$transactionID'") or die(mysql_error());
            }
                   $ret = ftp_nb_continue($conn_id);
           }
           if ($ret != FTP_FINISHED)
        {
                   print ("error uploading\n");
                   exit(1);
           }
        else
        {
            $fin = "-1";
            mysql_query("UPDATE ftp SET percentage='$fin' WHERE transactionID='$transactionID'");
        }

           f close($fp);
    }
}


?>
[/code]

Create the table structure
[code]
#
# Table structure for table `ftp`
#

CREATE TABLE ftp (
  transactionID int(11) NOT NULL default '0',
  percentage int(11) NOT NULL default '0'
) TYPE=MyISAM;
[/code]

There, a php/html progress bar with no javascript :) although it wont take a file off your PC and show the percentage as it goes, it WILL take a file from the webserver and put it on an FTP somewhere and show the percentage of that as it goes. It's a good example of how to do a php progress bar.. Dont ask for support on it, I did not create it heh

Remove spaces from the fopen and fclose functions.

Share this post


Link to post
Share on other sites
Thanks for that.. Although I strictly need something that will display a 'loading, please wait message' - while uploading a file from your local machine.

The javascript suggestion sounds good

i guess I could create a popup window using an 'onclick' event

could i then close that somehow, after execution?

Share this post


Link to post
Share on other sites
[!--quoteo(post=376958:date=May 25 2006, 05:20 AM:name=facelessface)--][div class=\'quotetop\']QUOTE(facelessface @ May 25 2006, 05:20 AM) [snapback]376958[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Thanks for that.. Although I strictly need something that will display a 'loading, please wait message' - while uploading a file from your local machine.

The javascript suggestion sounds good

i guess I could create a popup window using an 'onclick' event

could i then close that somehow, after execution?
[/quote]

never mind people - i've worked it out ;)

Thanks

Mike

Share this post


Link to post
Share on other sites
prismatic - script does not work. it does not update the progress bar. whatsoever. but (surprise!) it does say it's all done... when it's all done.

p.s.- "omg, I have this strictly PHP progress bar script... but I didn't make it so if it doesn't work.. don't ask support on it!"

... right. you either have a script that works, or you don't.

I was interested in seeing a working script. Even AFTER i had to do much debugging and tweaking just to make it do it's core job - actually xfering file in question - it still does not do what it's supposed to on the surface - showing a progress bar that updates (yeh i didn't see THAT one coming).

Share this post


Link to post
Share on other sites
[!--quoteo(post=377017:date=May 25 2006, 02:48 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 25 2006, 02:48 PM) [snapback]377017[/snapback][/div][div class=\'quotemain\'][!--quotec--]
prismatic - script does not work. it does not update the progress bar. whatsoever. but (surprise!) it does say it's all done... when it's all done.

p.s.- "omg, I have this strictly PHP progress bar script... but I didn't make it so if it doesn't work.. don't ask support on it!"

... right. you either have a script that works, or you don't.

I was interested in seeing a working script. Even AFTER i had to do much debugging and tweaking just to make it do it's core job - actually xfering file in question - it still does not do what it's supposed to on the surface - showing a progress bar that updates (yeh i didn't see THAT one coming).
[/quote]
And it doesn't actually do what the user originally wanted anyway - To enable a user to upload a file and receive feedback on its progress. I'm sure a script like the one posted has its uses, transfering a file from one server to another, but I just can't think of one right now...

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.