CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
simple progress bar in my script

 

First page Previous page 1 2 Next page Last page  View All


gerble1000
User

Aug 15, 2012, 3:43 AM

Post #1 of 31 (7235 views)
simple progress bar in my script Can't Post

i have an upload script with about 8 images and it can take up to 5 minutes of uploading and the user has no idea whats going on.
could somebody help me put a code into this script to show some sort of loading. even if its just
image 1 loaded
image 2 loading
image 2 loaded

and so on
here is my script








Code
#!/strawberry/perl/bin/perl -w  



use CGI::Carp qw( fatalsToBrowser );

#print "Content-Type: text/html\n\n";
#print "Content-Type: text/plain\n\n";
#print "Content-Type: text";


#######################################################################################
my $domainname = "mydomainname";
use CGI qw/ :standard /;

use DBI;

use File::Copy;
use File::Basename;
use CGI;
use strict;
use warnings;
use Image::Resize;




my $sold = param('group2');


my $result1 = param('advert');


my $result2 = param('car');
my $result3 = param('price');
my $result4 = param('year');
my $result5 = param('fuel');
my $result6 = param('color');
my $result7 = param('mileage');
my $result8 = param('gearbox');
my $result9 = param('engine');
my $result10 = param('body');
my $result11 = param('desc');
my $result12 = param('available');

my $result13 = param('group1');
my $result14 = param('model');
my $result15 = param('colortext');


if ($result6 eq "Other" )
{
$result6 = "$result15";
}



if ($sold eq "blank" )
{
$sold = "";
}

if ($result12 eq "blank" )
{
$result12 = "";
}




if ($result14 eq "" )
{
$result14 = "Not Specified";
}





if ($result13 eq "Just" )
{
goto JUST;
}


else
{


goto JUST0;
}



JUST0:


if ($sold eq "No" )
{
goto SKIP0;
}


else
{
open(F, '>:utf8', "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/available.txt");
print F "$sold";
close F;

goto SKIPend;
}




SKIP0:


open(F, '>:utf8', "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/car.txt");
print F "$result2";
close F;

open(F, '>:utf8', "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/price.txt");
print F "$result3";
close F;


open(F, '>:utf8', "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/year.txt");
print F "$result4";
close F;


open(F, '>:utf8', "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/fuel.txt");
print F "$result5";
close F;

open(F, '>:utf8', "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/color.txt");
print F "$result6";
close F;

open(F, '>:utf8', "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/mileage.txt");
print F "$result7";
close F;

open(F, '>:utf8', "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/gearbox.txt");
print F "$result8";
close F;

open(F, '>:utf8', "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/engine.txt");
print F "$result9";
close F;

open(F, '>:utf8', "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/body.txt");
print F "$result10";
close F;


open(F, '>:utf8', "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/desc.txt");
print F "$result11";
close F;

open(F, '>:utf8', "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/available.txt");
print F "$result12";
close F;

open(F, '>:utf8', "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/model.txt");
print F "$result14";
close F;



if ($result13 eq "No" )
{

goto SKIPend;
}


JUST:




$CGI::POST_MAX = 1024 * 50000;
my $safe_filename_characters = "a-zA-Z0-9_.-";
my $upload_dir = "$result1";

my $query = new CGI; my $filename = $query->param("uploadfile1");

if ($filename eq "" )
{
copy("noimage.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/1.png");
copy("noimagethumb1.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/thumb1.png");

goto SKIP1;
}



my $upload_filehandle = $query->upload("uploadfile1");
open ( UPLOADFILE, ">$result1/file.jpg" ) or die "failed to open '$upload_dir/1.jpg' $!"; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE;
copy("$result1/file.jpg","$result1/thumb1.jpg");
system("PhotoResize700x500ICO.exe $result1/file.jpg");
system("PhotoResize140x100ICO.exe $result1/thumb1.jpg");
move("$result1/file.jpg","file.jpg");
system('roundimage.php');
move("file.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/1.png");
move("$result1/thumb1.jpg","file.jpg");
system('roundimage.php');
move("file.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/thumb1.png");




SKIP1:

$CGI::POST_MAX = 1024 * 50000;
my $safe_filename_characters = "a-zA-Z0-9_.-";
my $upload_dir = "$result1";

my $query = new CGI; my $filename = $query->param("uploadfile2");

if ($filename eq "" )
{
copy("noimage.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/11.png");
copy("noimagethumb1.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/thumb11.png");
goto SKIP2;
}

my $upload_filehandle = $query->upload("uploadfile2");
open ( UPLOADFILE, ">$result1/file.jpg" ) or die "failed to open '$upload_dir/1.jpg' $!"; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE;
copy("$result1/file.jpg","$result1/thumb1.jpg");
system("PhotoResize700x500ICO.exe $result1/file.jpg");
system("PhotoResize140x100ICO.exe $result1/thumb1.jpg");
move("$result1/file.jpg","file.jpg");
system('roundimage.php');
move("file.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/11.png");
move("$result1/thumb1.jpg","file.jpg");
system('roundimage.php');
move("file.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/thumb11.png");

SKIP2:


$CGI::POST_MAX = 1024 * 50000;
my $safe_filename_characters = "a-zA-Z0-9_.-";
my $upload_dir = "$result1";

my $query = new CGI; my $filename = $query->param("uploadfile3");

if ($filename eq "" )
{
copy("noimage.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/111.png");
copy("noimagethumb1.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/thumb111.png");
goto SKIP3;
}

my $upload_filehandle = $query->upload("uploadfile3");
open ( UPLOADFILE, ">$result1/file.jpg" ) or die "failed to open '$upload_dir/1.jpg' $!"; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE;
copy("$result1/file.jpg","$result1/thumb1.jpg");
system("PhotoResize700x500ICO.exe $result1/file.jpg");
system("PhotoResize140x100ICO.exe $result1/thumb1.jpg");
move("$result1/file.jpg","file.jpg");
system('roundimage.php');
move("file.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/111.png");
move("$result1/thumb1.jpg","file.jpg");
system('roundimage.php');
move("file.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/thumb111.png");


SKIP3:


$CGI::POST_MAX = 1024 * 50000;
my $safe_filename_characters = "a-zA-Z0-9_.-";
my $upload_dir = "$result1";

my $query = new CGI; my $filename = $query->param("uploadfile4");

if ($filename eq "" )
{
copy("noimage.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/1111.png");
copy("noimagethumb1.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/thumb1111.png");
goto SKIP4;
}

my $upload_filehandle = $query->upload("uploadfile4");
open ( UPLOADFILE, ">$result1/file.jpg" ) or die "failed to open '$upload_dir/1.jpg' $!"; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE;
copy("$result1/file.jpg","$result1/thumb1.jpg");
system("PhotoResize700x500ICO.exe $result1/file.jpg");
system("PhotoResize140x100ICO.exe $result1/thumb1.jpg");
move("$result1/file.jpg","file.jpg");
system('roundimage.php');
move("file.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/1111.png");
move("$result1/thumb1.jpg","file.jpg");
system('roundimage.php');
move("file.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/thumb1111.png");


SKIP4:


$CGI::POST_MAX = 1024 * 50000;
my $safe_filename_characters = "a-zA-Z0-9_.-";
my $upload_dir = "$result1";

my $query = new CGI; my $filename = $query->param("uploadfile5");

if ($filename eq "" )
{
copy("noimage.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/11111.png");
copy("noimagethumb1.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/thumb11111.png");
goto SKIP5;
}

my $upload_filehandle = $query->upload("uploadfile5");
open ( UPLOADFILE, ">$result1/file.jpg" ) or die "failed to open '$upload_dir/1.jpg' $!"; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE;
copy("$result1/file.jpg","$result1/thumb1.jpg");
system("PhotoResize700x500ICO.exe $result1/file.jpg");
system("PhotoResize140x100ICO.exe $result1/thumb1.jpg");
move("$result1/file.jpg","file.jpg");
system('roundimage.php');
move("file.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/11111.png");
move("$result1/thumb1.jpg","file.jpg");
system('roundimage.php');
move("file.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/thumb11111.png");


SKIP5:


$CGI::POST_MAX = 1024 * 50000;
my $safe_filename_characters = "a-zA-Z0-9_.-";
my $upload_dir = "$result1";

my $query = new CGI; my $filename = $query->param("uploadfile6");

if ($filename eq "" )
{
copy("noimage.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/111111.png");
copy("noimagethumb1.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/thumb111111.png");
goto SKIP6;
}

my $upload_filehandle = $query->upload("uploadfile6");
open ( UPLOADFILE, ">$result1/file.jpg" ) or die "failed to open '$upload_dir/1.jpg' $!"; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE;
copy("$result1/file.jpg","$result1/thumb1.jpg");
system("PhotoResize700x500ICO.exe $result1/file.jpg");
system("PhotoResize140x100ICO.exe $result1/thumb1.jpg");
move("$result1/file.jpg","file.jpg");
system('roundimage.php');
move("file.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/111111.png");
move("$result1/thumb1.jpg","file.jpg");
system('roundimage.php');
move("file.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/thumb111111.png");




SKIP6:


$CGI::POST_MAX = 1024 * 50000;
my $safe_filename_characters = "a-zA-Z0-9_.-";
my $upload_dir = "$result1";

my $query = new CGI; my $filename = $query->param("uploadfile7");

if ($filename eq "" )
{
copy("noimage.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/1111111.png");
copy("noimagethumb1.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/thumb1111111.png");
goto SKIP7;
}

my $upload_filehandle = $query->upload("uploadfile7");
open ( UPLOADFILE, ">$result1/file.jpg" ) or die "failed to open '$upload_dir/1.jpg' $!"; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE;
copy("$result1/file.jpg","$result1/thumb1.jpg");
system("PhotoResize700x500ICO.exe $result1/file.jpg");
system("PhotoResize140x100ICO.exe $result1/thumb1.jpg");
move("$result1/file.jpg","file.jpg");
system('roundimage.php');
move("file.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/1111111.png");
move("$result1/thumb1.jpg","file.jpg");
system('roundimage.php');
move("file.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/thumb1111111.png");


SKIP7:


$CGI::POST_MAX = 1024 * 50000;
my $safe_filename_characters = "a-zA-Z0-9_.-";
my $upload_dir = "$result1";

my $query = new CGI; my $filename = $query->param("uploadfile8");

if ($filename eq "" )
{
copy("noimage.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/11111111.png");
copy("noimagethumb1.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/thumb11111111.png");
goto SKIPend;
}

my $upload_filehandle = $query->upload("uploadfile8");
open ( UPLOADFILE, ">$result1/file.jpg" ) or die "failed to open '$upload_dir/1.jpg' $!"; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE;
copy("$result1/file.jpg","$result1/thumb1.jpg");
system("PhotoResize700x500ICO.exe $result1/file.jpg");
system("PhotoResize140x100ICO.exe $result1/thumb1.jpg");
move("$result1/file.jpg","file.jpg");
system('roundimage.php');
move("file.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/11111111.png");
move("$result1/thumb1.jpg","file.jpg");
system('roundimage.php');
move("file.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/thumb11111111.png");






















SKIPend:


print "Content-type: text/html\n\n";
print "<html><head>\n";
print "</head>\n";
print "<body>";
print "<h1><center>$domainname</center></h1>";
print "<h1><center>SUCCESSFULLY CHANGED</center></h1>";

print "<h1><center><a href=\"http://www.$domainname.co.uk\">Back To Main Website</a></h1><br><br><br>\n\n";

print "<h1><center><a href=\"http://www.$domainname.co.uk/myadminpage.html\">Back To Admin Page</a></h1>\n";


i double posted because i made an error in the other post and i could not edit the page


Laurent_R
Veteran / Moderator

Aug 15, 2012, 4:40 AM

Post #2 of 31 (7229 views)
Re: [gerble1000] simple progress bar in my script [In reply to] Can't Post

I am not sure anyone will want to answer to your post containing 500 lines of poorly formatted code (why do you have such long lines in some places, up to 5 differents instructions and 182 characters long?), wrongly indented, all in one single chunk of code without even one single function (sub-routine) or one loop (except for reading a file), with lots of duplicated code, and filled with at least a dozen of gotos, making it really difficult to follow the logical execution path of your code.

You should really improve your coding practices. Use functions and loops, use lists, arrays and hashes, remove all the gotos, don't make lines longer that 80 characters or so, indent your code properly, use meaningful variable names, etc.

Uh, and read Damian Conway's "Perl best Practices".


gerble1000
User

Aug 15, 2012, 4:56 AM

Post #3 of 31 (7227 views)
Re: [Laurent_R] simple progress bar in my script [In reply to] Can't Post

i know my coding is poor but it does work ok.
could you explain why, when i put print"image1 loading";
and print"image2 loading"; inbetween uploading the images it does not display untill the very end and just shows all the prints .


FishMonger
Veteran / Moderator

Aug 15, 2012, 6:11 AM

Post #4 of 31 (7223 views)
Re: [gerble1000] simple progress bar in my script [In reply to] Can't Post

http://perldoc.perl.org/perlfaq5.html#How-do-I-flush/unbuffer-an-output-filehandle?-Why-must-I-do-this?


Laurent_R
Veteran / Moderator

Aug 15, 2012, 6:31 AM

Post #5 of 31 (7221 views)
Re: [gerble1000] simple progress bar in my script [In reply to] Can't Post

Hi,

If you do not have new line characters, your output will be buffered (i.e. kept in memory and printed at a later point). Change


Code
print"image1 loading";


to


Code
print"image1 loading \n";


That should do the trick if you just want to print a message such as "image1 loading".

If that is not sufficient, you can set $| to a true value (1, for example), this will disable buffering and force an immediate a flush after every write or print on the output being used (STDOUT in this case).


gerble1000
User

Aug 15, 2012, 6:32 AM

Post #6 of 31 (7220 views)
Re: [Laurent_R] simple progress bar in my script [In reply to] Can't Post

ideal thankyou


gerble1000
User

Aug 16, 2012, 9:25 AM

Post #7 of 31 (7203 views)
Re: [Laurent_R] simple progress bar in my script [In reply to] Can't Post

i tried the print"loading \n"; but no joy.
how would i implement this
"you can set $| to a true value (1, for example),"


wickedxter
User

Aug 16, 2012, 2:41 PM

Post #8 of 31 (7199 views)
Re: [gerble1000] simple progress bar in my script [In reply to] Can't Post

u need to change the perl buffer variable to 1 its the variable $| it will dump everything rather then hold the data to print out in a buffer and prints when print is invoked.. if that doesnt work then a javascript bar might work im sure u can find a free one.


Laurent_R
Veteran / Moderator

Aug 16, 2012, 11:17 PM

Post #9 of 31 (7186 views)
Re: [gerble1000] simple progress bar in my script [In reply to] Can't Post

Simply type:



$| = 1;


gerble1000
User

Aug 17, 2012, 8:29 AM

Post #10 of 31 (7173 views)
Re: [Laurent_R] simple progress bar in my script [In reply to] Can't Post

ok i have tried this and it still does the same and thats print everything once all images are uploaded :(


Laurent_R
Veteran / Moderator

Aug 17, 2012, 10:24 AM

Post #11 of 31 (7167 views)
Re: [gerble1000] simple progress bar in my script [In reply to] Can't Post

Then, the print statements are probably not at the right place.

And that would not surprise me so much, given the mess of your program.


gerble1000
User

Aug 18, 2012, 9:53 AM

Post #12 of 31 (7138 views)
Re: [Laurent_R] simple progress bar in my script [In reply to] Can't Post

ok i have done my best at cleaning the script up, here is what i have


Code
$| = 1;  



my $sold = param('group2');

my @skip = (1,2,3,4,5,6,7,8,9);
$skip[0] = "blank";
$skip[1] = param('skip1');
$skip[2] = param('skip2');
$skip[3] = param('skip3');
$skip[4] = param('skip4');
$skip[5] = param('skip5');
$skip[6] = param('skip6');
$skip[7] = param('skip7');
$skip[8] = param('skip8');







my @result = (1,2,3,4,5,6,7,8,9,10,11,12,13,14);
$result[0] = "blank";
$result[1] = param('car');
$result[2] = param('price');
$result[3] = param('year');
$result[4] = param('fuel');
$result[5] = param('color');
$result[6] = param('mileage');
$result[7] = param('gearbox');
$result[8] = param('engine');
$result[9] = param('body');
$result[10] = param('desc');
$result[11] = param('available');
$result[12] = param('model');

my $result1 = param('advert');
my $result14 = param('group1');
my $result15 = param('colortext');


if ($result[6] eq "Other" ){$result[6] = "$result15";}
if ($sold eq "blank" ){ $sold = "";}
if ($result[12] eq "blank" ){$result[12] = "";}
if ($result[13] eq "" ){$result14 = "Not Specified";}
if ($result14 eq "Just" ){goto JUST;}

else{}




if ($sold eq "No" ){goto SKIP0;}


else{

open(F, '>:utf8', "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result[1]/available.txt");
print F "$sold";
close F;

goto SKIPend;
}




SKIP0:


my @bulletins = ("blank","car","price","year","fuel","color","mileage","gearbox","engine","body","desc","available","model");

for(my $i = 1; $i <= 12; $i++){
open(F, '>:utf8', "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/$bulletins[$i].txt");
print F "$result[$i]";
close F;
}



if ($result14 eq "No" ){goto SKIPend;}


JUST:


$CGI::POST_MAX = 1024 * 50000;
my $safe_filename_characters = "a-zA-Z0-9_.-";


my $num1 = "1";
my $query = new CGI;
for(my $i = 1; $i <= 8; $i++){

print "Uploading Image $i \n";

my $filename = $query->param("uploadfile$i");

if (($filename eq "") & ($skip[$i] eq "") ){
copy("noimage.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/$num1.png");
copy("noimagethumb1.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/thumb$num1.png");
}


else{
if ($skip[$i] eq "skip"){}
else{
my $upload_filehandle = $query->upload("uploadfile$i");
open ( UPLOADFILE, ">$result1/file.jpg" ) or die "failed to open '$result1/$num1.jpg' $!"; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE;
copy("$result1/file.jpg","$result1/thumb1.jpg");
system("PhotoResize700x500ICO.exe $result1/file.jpg");
system("PhotoResize140x100ICO.exe $result1/thumb1.jpg");
move("$result1/file.jpg","file.jpg");
system('php roundimage.php');
move("file.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/$num1.png");
move("$result1/thumb1.jpg","file.jpg");
system('php roundimage.php');
move("file.png","C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/customers/$domainname/$result1/thumb$num1.png");
}
}
print "Completed Image $i \n";
$num1 = join "", $num1, "1";


}





SKIPend:

print "Content-type: text/html\n\n";
print "<html><head>\n";
print "</head>\n";
print "<body>";
print "<h1><center>$domainname</center></h1>";
print "<h1><center>SUCCESSFULLY CHANGED</center></h1>";


i have put the print commands in the for loop but i am still not getting the desire results, i am getting the results at the end of the script,


Laurent_R
Veteran / Moderator

Aug 18, 2012, 10:57 AM

Post #13 of 31 (7129 views)
Re: [gerble1000] simple progress bar in my script [In reply to] Can't Post

Hi,

I don't see how this printing would be buffered. This should work.

Possibly it is not the download of the images which is taking a lot of time, but some other part of your code.

I think you should time the whole thing.

One first approach is to change your code like this:


Code
# ... 
for my $i (1..8) {
my $date = gmtime(time);
print "$date : Uploading Image $i \n";
my $filename = $query->param("uploadfile$i");
# ...


Maybe you'll find out that the upload is actually faster than you think and that the program is spending a lot of time somewhere else.

In which case you should pour more of these performance profiling prints.

Note that there are a number of good profiling modules on the CPAN, but it won't work so long as you don't use functions to structure your code.


gerble1000
User

Aug 18, 2012, 11:14 AM

Post #14 of 31 (7128 views)
Re: [Laurent_R] simple progress bar in my script [In reply to] Can't Post

ok here is my results after uploading 8 small images around 100kb each.
Sat Aug 18 18:10:51 2012 : Uploading Image 1 Sat Aug 18 18:10:57 2012 : Uploading Image 2 Sat Aug 18 18:11:02 2012 : Uploading Image 3 Sat Aug 18 18:11:08 2012 : Uploading Image 4 Sat Aug 18 18:11:14 2012 : Uploading Image 5 Sat Aug 18 18:11:19 2012 : Uploading Image 6 Sat Aug 18 18:11:25 2012 : Uploading Image 7 Sat Aug 18 18:11:31 2012 : Uploading Image 8


Laurent_R
Veteran / Moderator

Aug 18, 2012, 11:44 AM

Post #15 of 31 (7125 views)
Re: [gerble1000] simple progress bar in my script [In reply to] Can't Post

Strange, your output seems to indicate that you don't have the "\n" in your print statement, because each print should be on a new line, you should get something like this:


Code
Sat Aug 18 18:10:51 2012 : Uploading Image 1  
Sat Aug 18 18:10:57 2012 : Uploading Image 2
Sat Aug 18 18:11:02 2012 : Uploading Image 3



FishMonger
Veteran / Moderator

Aug 18, 2012, 11:48 AM

Post #16 of 31 (7125 views)
Re: [Laurent_R] simple progress bar in my script [In reply to] Can't Post

You don't need to use subroutines to be able to profile scripts, but this script is so poorly written it's not even worth spending the time to profile it.

IMO, it should be thrown out and completely rewritten.


gerble1000
User

Aug 18, 2012, 12:06 PM

Post #17 of 31 (7122 views)
Re: [FishMonger] simple progress bar in my script [In reply to] Can't Post

if i was as good as you i would be able to do that, but this is as good as i get for the minute :(
im learning as i go along as i only got into programming a few months ago really.
but as i progress the better the scripts will look.
do you have any pointers apart from "it should be thrown out"


gerble1000
User

Aug 18, 2012, 12:15 PM

Post #18 of 31 (7117 views)
Re: [Laurent_R] simple progress bar in my script [In reply to] Can't Post

ok i was using this command at the top of the script
print "Content-Type: text/html\n\n";
i have now replaced it for
print "Content-Type: text/plain\n\n";
and the output is better but still all at once


Code
Sat Aug 18 19:12:59 2012 : Uploading Image 1  
Sat Aug 18 19:13:05 2012 : Uploading Image 2
Sat Aug 18 19:13:11 2012 : Uploading Image 3
Sat Aug 18 19:13:16 2012 : Uploading Image 4
Sat Aug 18 19:13:22 2012 : Uploading Image 5
Sat Aug 18 19:13:27 2012 : Uploading Image 6
Sat Aug 18 19:13:33 2012 : Uploading Image 7
Sat Aug 18 19:13:39 2012 : Uploading Image 8
Content-type: text/html

<html><head>
</head>
<body><h1><center>g-e-s</center></h1><h1><center>SUCCESSFULLY CHANGED</center></h1><h1><center><a href="http://www.g-e-s.co.uk">Back To Main Website</a></h1><br><br><br>

<h1><center><a href="http://www.g-e-s.co.uk/admin337648769.html">Back To Admin Page</a></h1>



(This post was edited by gerble1000 on Aug 18, 2012, 12:16 PM)


FishMonger
Veteran / Moderator

Aug 18, 2012, 12:54 PM

Post #19 of 31 (7114 views)
Re: [gerble1000] simple progress bar in my script [In reply to] Can't Post

Here are a few recommendation to start with.

Get rid of all of the goto statements. In there place, you should be using either an if/else construct, or call a subroutine, or a combination of both.

You're intermixing the functional and OO interface of the CGI module. Don't do that. Use one or the other, but not both.

Using the @skip and @result arrays don't make any sense and only serve to obfuscate the code. Instead, load all of your params in a hash, which only takes a singe line of code to accomplish. Or, if you must, use the param method to assign them to individual vars and use var names that indicate what they hold, such as using var names that match the field names.

The field name for all of the upload fields should be the same which allows you to easily put then into an array which you loop over when uploading.

I don't know what you're trying to accomplish with outputting each of the @bulletins fields to individual files, but I can assure you that you're using the wrong approach to accomplish that goal.

The resizing and corner rounding of the images can and probably should be done by using the proper CPAN module rather than doing the system calls.

Here's an example how your script should begin.

Code
#!/strawberry/perl/bin/perl 

use strict;
use warnings;
use CGI;
use CGI::Carp qw( fatalsToBrowser warningsToBrowser );
use File::Copy;
use File::Basename;
use Image::Resize;

$| = 1;
$CGI::POST_MAX = 1024 * 50000;

my $cgi = CGI->new;
print $cgi->header, $cgi->start_html;
warningsToBrowser(1);

# this loads all of the submitted params into a hash
# where the keys are the field names
my %param = $cgi->Vars;

# this is how to get the list of uploads
# assuming they all had the same value for the 'name' attribute
my @upload_files = split("\0", $param{'uploadfile'});

# this varname is a little verbose, but I know/understand where you got it
my $safe_filename_characters = "a-zA-Z0-9_.-";



gerble1000
User

Aug 18, 2012, 1:42 PM

Post #20 of 31 (7106 views)
Re: [FishMonger] simple progress bar in my script [In reply to] Can't Post

thank you this is great.
my script runs 100x faster not sure why though,
and it prints on every upload which is great,
but it doesn't seem to use the \n as it just scrolls across the screen,
also i like the sound of this here
my @upload_files = split("\0", $param{'uploadfile'});

unsure how to use it as when i try to print the
$upload_files[0] i don't get anything onscreen to show that it has the parameter .
or is this a different kind of array


FishMonger
Veteran / Moderator

Aug 18, 2012, 1:53 PM

Post #21 of 31 (7101 views)
Re: [gerble1000] simple progress bar in my script [In reply to] Can't Post


Quote
it doesn't seem to use the \n as it just scrolls across the screen

Since the doctype is html, you need to use the <br> html tag instead of (or in addition to) using \n.


Quote
unsure how to use it as when i try to print the
$upload_files[0] i don't get anything onscreen to show that it has the parameter .


Did you make the respective change to the form? Meaning, did you change the name attribute on the file upload fields so that they are all using the same value, or are they still numbered?


gerble1000
User

Aug 18, 2012, 2:01 PM

Post #22 of 31 (7099 views)
Re: [FishMonger] simple progress bar in my script [In reply to] Can't Post

i change the form names to uploadfile
instead of
uploadfile1
uploadfile2


FishMonger
Veteran / Moderator

Aug 18, 2012, 2:07 PM

Post #23 of 31 (7096 views)
Re: [gerble1000] simple progress bar in my script [In reply to] Can't Post

So, you're saying that it doesn't print the filenames, but it does upload the files?

Please post your updated script and the html form.


gerble1000
User

Aug 18, 2012, 2:09 PM

Post #24 of 31 (7093 views)
Re: [FishMonger] simple progress bar in my script [In reply to] Can't Post

my bad, i forgot to refresh the html page, works lovely :)
im going to have a play and use the same technique for the other paramaters,
what does this actually do
my %param = $cgi->Vars;
oh and does the "0" in this line start the array at [0]
my @upload_files = split("\0", $param{'uploadfile'});
if so could i start it at 1 like this
my @upload_files = split("\1", $param{'uploadfile'});


(This post was edited by gerble1000 on Aug 18, 2012, 2:16 PM)


Laurent_R
Veteran / Moderator

Aug 18, 2012, 2:24 PM

Post #25 of 31 (7089 views)
Re: [gerble1000] simple progress bar in my script [In reply to] Can't Post


In Reply To
thank you this is great.
my script runs 100x faster not sure why though,
and it prints on every upload which is great


I told you that the problem was probably elsewhere. Your program was probably spending huge amount of time doing stupid and useless tasks repeteadly, but it was so poorly structured, that I certainly would not want to try understanding its behavior.

Never, ever, write a goto in Perl, this is really *bad* (except perhaps in very very specific cases for a very special flavor of goto, which has to do with Perl's black magics and nothing to do with the type of code you are writing).

First page Previous page 1 2 Next page Last page  View All
 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives