Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

link errors

by eoin (Monk)
on Sep 19, 2003 at 23:32 UTC ( [id://292784]=perlquestion: print w/replies, xml ) Need Help??

eoin has asked for the wisdom of the Perl Monks concerning the following question:

Dear Fellow Monks,

I have come to you with numerous problems before that through blindness and lack of vision (mostly the first) I hadn't been able to solve. And I am very greatful for all the help I have gotten so far.

This time though I not really sure that it is a problem that would qualify to be here, but how and ever...

I've been working on this picture viewer for the Internet. With the following functions:

  • Upload pictures
  • Create an album
  • View the pictures in thumbnail
  • And then if you click on the pic in full size.

The script I use to view the albums and the full size images are one in the same.
Now the problem that I have is that the script works perfectly when viewing the thumbnails but when you go and click on an image to view is full size I get this "Would you like to download this file pop-up-box". Asking would I like to download a file named "albums" with no file type from http://eoinmurphy.netfirms.com

Now I've gone through the script looking for anything that might cause this but I've drawn a blank.
(I know that I am going to get a bollocking for not using CGI to generate shtml but that's not the problem. It worked before but I've done quite a bit of changing and it doesn't wor now)

Heres the code

#!/usr/bin/perl -w use strict; use warnings; use diagnostics; use CGI; my $q = new CGI; my $status = $q->param('status'); my $album = $q->param('album') ; my $img = $q->param('pic') ; my $user = $q->param('user') ; my @html; my $row; my $src; my $pic; my $html; my $viewersrc = "http://eoinmurphy00.netfirms.com/albums/$album/$img"; if ($status eq "viewall"){ $html = viewall(); } elsif ($status eq "viewer"){ $html = viewer($viewersrc, $user); } print qq(Content-type: text/html\n $html); sub viewall{ my $pic; my $dir = "../www/albums/$album"; opendir DIR, "$dir" or die $!; my @images= grep /\.img/, readdir DIR; closedir DIR; my $ttlcounter = "0"; my $tmpcounter = "0"; foreach $pic (@images) { $src = "http://eoinmurphy00.netfirms.com/albums/$album/$pic"; if ($tmpcounter == 3) { $tmpcounter = "0"; $row = qq(</tr> <tr> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td>\&nbsp;</td> <td><a href="http://eoinmurphy00.netfirms.com/cgi-bin/a +lbums.cgi?status=viewer&album=$album&pic=$pic&user=$user"><img src="$ +src" width="175" height="129"></a></td> <td>\&nbsp;</td> <td>\&nbsp;</td>); push @html, $row; $tmpcounter++; } else { $row = qq(<td>\&nbsp;</td> <td><a href="http://eoinmurphy00.netfirms.com/cgi-bin/a +lbums.cgi?status=viewer&album=$album&pic=$pic&user=$user"><img src="$ +src" width="175" height="129"></a></td> <td>\&nbsp;</td> <td>\&nbsp;</td>); push @html, $row; $tmpcounter++; } } my $album_html = qq( <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="GENERATOR" content="Microsoft FrontPage Express 2.0"> <title>Apres Bonne Anse Plage</title> </head> <body bgcolor="#000098" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF"> <p align="center">&nbsp;</p> <div align="center"><center> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="5"><img src="http://eoinmurphy00.netfirms.com/ima +ges/title.jpg" width="780" height="224"><br> </td> </tr> <tr> <td colspan="5"><div align="center"><center><table border="1" cellpadding="0" cellspacing="0" width="780"> <tr> <td align="center" bordercolor="#FFFFFF"><p align="center"><font color="#FFFFFF" size="6" face="ITC Zapf Chancery"><strong><u>$album</u></strong +></font></p> <hr> <div align="center"><center><table border="0" cellpadding="0" cellspacing="0"> <tr> @html </table> </center></div><p align="center"><font color="#FFFFFF" face="Abbess"><em></em></font>&nbsp;</ +p> <div align="center"><center><table border="1" cellpadding="0" cellspacing="0" width="775"> <tr> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=home&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Home</u></ +strong></font></a></p> </td> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=albums&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Albums</u> +</strong></font></a></p> </td> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=upload&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Upload</u> +</strong></font></a></p> </td> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=contact&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Contact </u></strong></font></a></p> </td> </tr> </table> </center></div></td> </tr> </table> </center></div><p><font color="#FFFFFF" face="Abbess"><img src="http://eoinmurphy00.netfirms.com/images/border.jpg" width +="780" height="51"></font></p> </td> </tr> </table> </center></div> </body> </html>); return $album_html } sub viewer{ my( $src, $user ) = @_; my @splitsrc = split(/\//, $src); my $currentpic = pop(@splitsrc); print $currentpic; my @imgnmbr = ($currentpic =~ /\d+/g); my $nextimgnmbr = $imgnmbr[0]; my $previmgnmbr = $imgnmbr[0]; $nextimgnmbr++; $previmgnmbr--; my $nextpic = "pic$nextimgnmbr.img"; my $prevpic = "pic$previmgnmbr.img"; my $next_html = "http://eoinmurphy00.netfirms.com/cgi-bin/albums.cgi?s +tatus=viewer&album=$album&pic=$nextpic&user$user"; my $previous_html = "http://eoinmurphy00.netfirms.com/cgi-bin/albums.c +gi?status=viewer&album=$album&pic=$prevpic&user$user"; my $viewer_html = qq( <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="GENERATOR" content="Microsoft FrontPage Express 2.0"> <title>Apres Bonne Anse Plage</title> </head> <body bgcolor="#000098" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF"> <p align="center">&nbsp;</p> <div align="center"><center> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="5"><img src="http://eoinmurphy00.netfirms.com/ima +ges/title.jpg" width="780" height="224"><br> </td> </tr> <tr> <td colspan="5"><div align="center"><center><table border="1" cellpadding="0" cellspacing="0" width="780"> <tr> <td align="center" bordercolor="#FFFFFF"><div align="center"><center><table border="0" cellpadding="0" cellspacing="0" width="600"> <tr> <td colspan="2"><p align="center"><font color="#FFFFFF" size="7" face="ITC Zapf Chancery"><strong><u>$album</u> +</strong></font></p> </td> </tr> <tr> <td width="300"><p align="center"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><u><a href="$previous +_html">Previous</a></u></font></p> </td> <td width="300"><p align="center"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><u><a href="$next_htm +l">Next</a></u></font></p> </td> </tr> </table> </center></div><hr> <p><img src="$src"></p><p>&nbsp;</p> <div align="center"><center><table border="1" cellpadding="0" cellspacing="0" width="775"> <tr> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=home&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Home</u></ +strong></font></a></p> </td> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=albums&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Albums</u> +</strong></font></a></p> </td> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=upload&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Upload</u> +</strong></font></a></p> </td> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=contact&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Contact </u></strong></font></a></p> </td> </tr> </table> </center></div></td> </tr> </table> </center></div><p><font color="#FFFFFF" face="Abbess"><img src="http://eoinmurphy00.netfirms.com/images/border.jpg" width +="780" height="51"></font></p> </td> </tr> </table> </center></div> </body> </html> ); return $viewer_html }

I appriciate any and all help

Thanks
All the Best, Eoin...

If everything seems to be going well, you obviously don't know what the hell is going on.

Replies are listed 'Best First'.
Re: link errors
by Abigail-II (Bishop) on Sep 20, 2003 at 01:05 UTC
    The server is probably not sending the right content type.

    But I'm wondering, why do you create everything dynamic? Unless all your pictures are of polar bears in snow and mist (which compresses nicely), the size of the HTML is dwarved by the size of the images. Why not create a bunch of static HTML files? That reduces the load on the server, and will make that users can load the images faster. It's also far more cache friendly. Just regenerate your static set if you add images to an album.

    Abigail

      Yeah i've been thinking ofchanging the whole site to one static htmlfile which is the external frame and I create the internal frame.

      Anyway I've thought about the fact that it could be a problem witht the content type but it might be, because I chose to download the file it offers and It was a file ful of the HTML that was meant to be sent to the browser.

      I managed to route out and older version of the script before I did alot of the editing. This script works and I've compared it to the new one but I can't find any diffenrence that could cause a change.

      #!/usr/bin/perl -w use strict; use warnings; use diagnostics; use CGI; my $q = new CGI; my $status = $q->param('status'); my $album = $q->param('album') ; my $img = $q->param('pic') ; my $user = $q->param('user') ; my @html; my $row; my $src; my $pic; my $html; my $viewersrc = "http://eoinmurphy00.netfirms.com/albums/$album/$img"; if ($status eq "viewall"){ $html = viewall(); } elsif ($status eq "viewer"){ $html = viewer($viewersrc, $user); } print qq(Content-type: text/html\n $html); sub viewall{ my $pic; open LOG, ">logfile" or die $!; my $dir = "../www/albums/$album"; opendir DIR, "$dir" or die $!; my @images= grep /\.img/, readdir DIR; closedir DIR; print LOG "\@images contains ============== @images\n\n"; my $counter = "0"; foreach $pic (@images){ $src = "http://eoinmurphy00.netfirms.com/albums/$album/$pic"; print LOG "My img src is $src for pic $pic\n"; if ($counter == 3){ $counter = "0"; $row = qq(</tr> <tr> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td>\&nbsp;</td> <td><a href="http://eoinmurphy00.netfirms.com/cgi-bin/albu +ms.cgi?status=viewer&album=$album&pic=$pic&user=$user"><img src="$src +" width="175" height="129"></a></td> <td>\&nbsp;</td> <td>\&nbsp;</td>); push @html, $row; $counter++; } else{ $row = qq(<td>\&nbsp;</td> <td><a href="http://eoinmurphy00.netfirms.com/cgi-bin/albu +ms.cgi?status=viewer&album=$album&pic=$pic"><img src="$src" width="17 +5" height="129"></a></td> <td>\&nbsp;</td> <td>\&nbsp;</td>); push @html, $row; $counter++; } print LOG @html; } my $album_html = qq( <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="GENERATOR" content="Microsoft FrontPage Express 2.0"> <title>Apres Bonne Anse Plage</title> </head> <body bgcolor="#000098" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF"> <p align="center">&nbsp;</p> <div align="center"><center> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="5"><img src="http://eoinmurphy00.netfirms.com/ima +ges/title.jpg" width="780" height="224"><br> </td> </tr> <tr> <td colspan="5"><div align="center"><center><table border="1" cellpadding="0" cellspacing="0" width="780"> <tr> <td align="center" bordercolor="#FFFFFF"><p align="center"><font color="#FFFFFF" size="6" face="ITC Zapf Chancery"><strong><u>$album</u></strong +></font></p> <hr> <div align="center"><center><table border="0" cellpadding="0" cellspacing="0"> <tr> @html </table> </center></div><p align="center"><font color="#FFFFFF" face="Abbess"><em></em></font>&nbsp;</ +p> <div align="center"><center><table border="1" cellpadding="0" cellspacing="0" width="775"> <tr> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=home&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Home</u></ +strong></font></a></p> </td> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=albums&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Albums</u> +</strong></font></a></p> </td> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=upload&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Upload</u> +</strong></font></a></p> </td> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=contact&user=$user"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Contact </u></strong></font></a></p> </td> </tr> </table> </center></div></td> </tr> </table> </center></div><p><font color="#FFFFFF" face="Abbess"><img src="http://eoinmurphy00.netfirms.com/images/border.jpg" width +="780" height="51"></font></p> </td> </tr> </table> </center></div> </body> </html>); return $album_html } sub viewer{ my( $src, $username ) = @_; my $next_html; my $previous_html; my $viewer_html = qq( <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="GENERATOR" content="Microsoft FrontPage Express 2.0"> <title>Apres Bonne Anse Plage</title> </head> <body bgcolor="#000098" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF"> <p align="center">&nbsp;</p> <div align="center"><center> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="5"><img src="http://eoinmurphy00.netfirms.com/ima +ges/title.jpg" width="780" height="224"><br> </td> </tr> <tr> <td colspan="5"><div align="center"><center><table border="1" cellpadding="0" cellspacing="0" width="780"> <tr> <td align="center" bordercolor="#FFFFFF"><div align="center"><center><table border="0" cellpadding="0" cellspacing="0" width="600"> <tr> <td colspan="2"><p align="center"><font color="#FFFFFF" size="7" face="ITC Zapf Chancery"><strong><u>$album</u> +</strong></font></p> </td> </tr> <tr> <td width="300"><p align="center"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><u>Previous</u></font +></p> </td> <td width="300"><p align="center"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><u>Next</u></font></p +> </td> </tr> </table> </center></div><hr> <p><img src="$src"></p><p>&nbsp;</p> <div align="center"><center><table border="1" cellpadding="0" cellspacing="0" width="775"> <tr> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=home&user=$username"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Home</u></ +strong></font></a></p> </td> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=albums&user=$username"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Albums</u> +</strong></font></a></p> </td> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=upload&user=$username"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Upload</u> +</strong></font></a></p> </td> <td align="center" valign="bottom" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF"><p align="center"><a href="http://eoinmurphy00.netfirms.com/cgi-bin +/main.cgi?status=contact&user=$username"><font color="#FFFFFF" size="5" face="ITC Zapf Chancery"><strong><u>Contact </u></strong></font></a></p> </td> </tr> </table> </center></div></td> </tr> </table> </center></div><p><font color="#FFFFFF" face="Abbess"><img src="http://eoinmurphy00.netfirms.com/images/border.jpg" width +="780" height="51"></font></p> </td> </tr> </table> </center></div> </body> </html> ); return $viewer_html }
      If you can see something wrong with this I'd love if you could point it out.

      Thanks for the help so far

      All the Best, Eoin...

      If everything seems to be going well, you obviously don't know what the hell is going on.

        Observation: In your newer code, you had the following code in your viewer sub:
        my $next_html = "http://.../albums.cgi?...&pic=$nextpic&user$user";
        You missed an equal '=' from the URL, should be user=$user.
        Also in the same viewer sub, you had two lines:
        my $currentpic = pop(@splitsrc); print $currentpic;
        Where the print $currentpic; bit will print the image name to the standard out, which will certainly get printed before your content-type header, and this of cause will interfere with how the HTML is handled by the client browser. Remember that anything printed to STDOUT will get sent to the target browser.
Re: link errors
by Roger (Parson) on Sep 20, 2003 at 11:34 UTC
    This is because the internet browser could not automatically determine the format of your full-size image from the image extension and the file header.

    The easiest way to fix this would be changing the fullsized images to jpg or png (etc) format.

    Otherwise you have to set up the MIME type of the images in the content header to tell the browser what type of image it is. If the image is not in a standard format that internet explorer understands, then you need to supply custom plug-in's (can set up via tools/folder-options/file-type).

      I've solved that problem thatks to your help but as I was expanding the script perl threw up these crazy errors:
      syntax error at albums.cgi line 102, near "else"
      syntax error at albums.cgi line 110, near "elsif"
      albums.cgi had compilation errors (#1)
          (F) The final summary message when a perl -c fails.
      
      Uncaught exception from user code:
              syntax error at albums.cgi line 102, near "else"
      syntax error at albums.cgi line 110, near "elsif"
      albums.cgi had compilation errors.
      
      Now I've gone to the lines in question and searched the surrounding lines but cannot find a problem. I you seemed to be able to spot things that I cannot. Any help is greatly appriciated.
      Thanks
      All the Best, Eoin...

      If everything seems to be going well, you obviously don't know what the hell is going on.

        Are you programming on Windows or Unix? If on windows, I recommend the following free programmer's editor: Context. "http://www.fixedsys.com/context/".

        If on Unix, then Emacs or Nedit, which are brilliant at sytax highlighting.

        My recommendation is to use a syntax highlighting editor, then you can spot compilation / typo mistakes at a glance.

        It would be helpful if you could post your new code so the monks can have a look at what is happening at the lines of error.

        Cheers, Roger.
Re: link errors
by Anonymous Monk on Sep 20, 2003 at 00:37 UTC
    That's a http/browser problem (depending on how you look at it).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://292784]
Approved by jdtoronto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-20 03:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found