Re: teaching myself perl - stumped on this one!
From: Abhinav (Me_at_myco.com)
Date: 03/08/04
- Next message: David: "Ignoring an element in a list"
- Previous message: Tad McClellan: "Re: [newbie] Filehandles and physical files"
- In reply to: Martin Livingston: "teaching myself perl - stumped on this one!"
- Next in thread: Martin Livingston: "Re: teaching myself perl - stumped on this one!"
- Reply: Martin Livingston: "Re: teaching myself perl - stumped on this one!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 08 Mar 2004 10:40:40 +0530
Hi Martin,
Martin Livingston wrote:
> Hi,
>
> I bought a book ( PERL and CGI For the World Wide Web - Elizabeth Castro )
> learn the basics. I have put together a dozen or so working scripts but this
> one has me stumped.
>
> This is a "real world" exercise. I am putting together a "cookbook" for a
> friend. She fills in a form with the recipe details and selects a image file
> to appear on the finished web page. When she "submits" the form it returns a
> copy of the preview page with the image in place where the image file is
> stored in a temporary location on my server. Up to this point everything
> works just fine.
>
> If she is happy with the preview page, she "submits" this page to be stored
> on the server. The html gets written correctly to the server but the image
> file only creates the file name without any data in the permanent images
> directory. However, the script deletes the old file properly.
>
> Here is the first portion of the script (with the absolute paths blanked
> out). I am sure I am just using the FILEHANDLES incorrectly and would
> appreciate any help available out there. I used comment lines to explain
> what I am trying to do.
>
> Thanks
> Martin L.
>
> #!/usr/bin/perl
> use CGI ':standard';
>
> #import the data from the hidden fields from the recipe preview page
>
> $catagory=param("catagory");
> $name=param("name");
> $description=param("description");
> $source=param("source");
> $origin=param("origin");
> $ingredients=param("ingredients");
> $method=param("method");
> $service=param("service");
> $picture=param("picture");
> $filename= param("filename");
> $imgfilename = param("imgfilename");
>
> #build the meta tags for the website search engine
>
> $meta = $catagory . " " . $name . " " . $description . " " . $source . " " .
> $origin;
>
> #see if picture file was uploaded
>
> if ($picture) {
>
> #get image from temporary image directory
>
> open (TEMPORARY, "</xxx/xxx/x/xx/xx/xxxxx/web/nugget/temp/$imgfilename");
>
> $temp_img=(TEMPORARY);
>
> close (TEMPORARY);
>
> #delete temporary image file
>
> unlink ("/xxx/xxx/x/xx/xx/xxxxx/web/nugget/temp/$imgfilename");
>
> #copy image file to the cookbook images directory
>
> open (IMAGEFILE,
> ">>/xxx/xxx/x/xx/xx/xxxxx/web/nugget/cookbook/images/$imgfilename");
>
This cold be a red herring (and Im nerw to perl too ! ) but shouldn't
the above FILEHANDLE be opened with ">" instead of ">>" ?
> print IMAGEFILE "$temp_img";
>
> close (IMAGEFILE);
>
> }
>
> #Copy html to the appropriate folder in the cookbook directory
>
> open (PAGEFILE,
> ">/xxx/xxx/x/xx/xx/xxxxx/web/nugget/cookbook/$catagory/$filename");
> print PAGEFILE qq(<html>\n<head>\n<title>$name</title>\n</head>\n<body>\n);
> print PAGEFILE qq(<META NAME=description CONTENT=$description>\n);
> print PAGEFILE qq(<META NAME=keywords CONTENT= $meta>\n);
> print PAGEFILE qq(<body bgcolor="#e6e6fa" TOPMARGIN=5 LEFTMARGIN=2
> MARGINHEIGHT=0 MARGINWIDTH=2>\n);
> print PAGEFILE qq(<table width=600 align=center CELLPADDING=0 border=0
> CELLSPACING=0>\n);
>
>
Please let me know if thats the problem or I've pointed out a no-go .. :)
Regards
Abhinav
- Next message: David: "Ignoring an element in a list"
- Previous message: Tad McClellan: "Re: [newbie] Filehandles and physical files"
- In reply to: Martin Livingston: "teaching myself perl - stumped on this one!"
- Next in thread: Martin Livingston: "Re: teaching myself perl - stumped on this one!"
- Reply: Martin Livingston: "Re: teaching myself perl - stumped on this one!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|