Jump to content


Photo

progress bar...


  • Please log in to reply
14 replies to this topic

#1 facelessface

facelessface
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 24 May 2006 - 09:18 PM

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?!

#2 appeland

appeland
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 24 May 2006 - 10:28 PM

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

#3 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 24 May 2006 - 10:37 PM

[!--quoteo(post=376820:date=May 24 2006, 04:18 PM:name=facelessface)--][div class=\'quotetop\']QUOTE(facelessface @ May 24 2006, 04:18 PM) View Post[/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

#4 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 24 May 2006 - 10:48 PM

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!
follow me on twitter @PHPsycho

#5 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 25 May 2006 - 03:10 AM

[!--quoteo(post=376833:date=May 24 2006, 05:48 PM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ May 24 2006, 05:48 PM) View Post[/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 :)

#6 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 25 May 2006 - 04:29 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#7 facelessface

facelessface
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 25 May 2006 - 09:35 AM

[!--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) View Post[/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

#8 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 25 May 2006 - 09:42 AM

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.

#9 facelessface

facelessface
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 25 May 2006 - 09:49 AM

[!--quoteo(post=376943:date=May 25 2006, 04:42 AM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ May 25 2006, 04:42 AM) View Post[/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


#10 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 25 May 2006 - 10:12 AM

"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
<?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>");


?>

progress.php
<?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>");
}

?>

upload.php
<?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);
    }
}


?>

Create the table structure
#
# Table structure for table `ftp`
#

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

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.

#11 facelessface

facelessface
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 25 May 2006 - 10:20 AM

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?

#12 facelessface

facelessface
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 25 May 2006 - 11:46 AM

[!--quoteo(post=376958:date=May 25 2006, 05:20 AM:name=facelessface)--][div class=\'quotetop\']QUOTE(facelessface @ May 25 2006, 05:20 AM) View Post[/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

#13 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 25 May 2006 - 01:21 PM

what was your solution?
wisewood: proven fact, I am both wise, and wooden.

#14 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 25 May 2006 - 01:48 PM

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).
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#15 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 25 May 2006 - 03:25 PM

[!--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) View Post[/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...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users