D
Doug H
I am a fairly new Perl programmer so am hoping that my problem is just a
simple
mistake that someone can easily help me with.
I have a short Perl script that gets some information from a form on a web
page
and then uploads a picture file to the web site. This part works fine. My
problem
occurs when I try to rename the file that was just uploaded. My coding is as
follows:
#!/usr/local/bin/perl -wT
use CGI;
#get info about file to upload
$upload_dir = "/d4/d8/pscc.shawbiz.ca/html/";
$query = new CGI; $filename = $query->param("uploadfile");
#get other information to process
$picnum= $query->param("picnum");
$pcomm= $query->param("pcomm");
$wpage= $query->param("wpage");
#do the uploading
$filename =~ s/.*[\/\\](.*)/$1/;
$upload_filehandle = $query->upload("uploadfile");
open UPLOADFILE, ">$upload_dir/$filename";
while ( <$upload_filehandle> )
{
print UPLOADFILE;
}
close UPLOADFILE;
#rename the uploaded file
my $newfilename="/d4/d8/pscc.shawbiz.ca/html/bunnysredone.jpg";
rename ("/d4/d8/pscc.shawbiz.ca/html/bunnys.jpg",$newfilename);
.....
etc (the rest just shows a web page showing the results)
In the above the renaming of the uploaded file works. It renames
the picture file from 'bunnys.jpg' to 'bunnysredone.jpg'. What I
need, though, is to have the new picture name created from
the picture number that was uploaded (the value of $picnum). So
I replaced the line for $newfilename to be
my $newfilename="/d4/d8/pscc.shawbiz.ca/html/pic".$picnum.".jpg";
With this change, the renaming no longer works. If I comment out
the actual rename line of code and display the value of $newfilename
in the output, it shows exactly what I would have expected it to
be
eg
/d4/d8/pscc.shawbiz.ca/html/pic5.jpg
where the 5 represents the current value for $picnum.
I do not see what I am doing wrong. Can anyone help? When I get
this working I would also like to use the same technique to set
the value of the old name in the rename line.
Thank you.
simple
mistake that someone can easily help me with.
I have a short Perl script that gets some information from a form on a web
page
and then uploads a picture file to the web site. This part works fine. My
problem
occurs when I try to rename the file that was just uploaded. My coding is as
follows:
#!/usr/local/bin/perl -wT
use CGI;
#get info about file to upload
$upload_dir = "/d4/d8/pscc.shawbiz.ca/html/";
$query = new CGI; $filename = $query->param("uploadfile");
#get other information to process
$picnum= $query->param("picnum");
$pcomm= $query->param("pcomm");
$wpage= $query->param("wpage");
#do the uploading
$filename =~ s/.*[\/\\](.*)/$1/;
$upload_filehandle = $query->upload("uploadfile");
open UPLOADFILE, ">$upload_dir/$filename";
while ( <$upload_filehandle> )
{
print UPLOADFILE;
}
close UPLOADFILE;
#rename the uploaded file
my $newfilename="/d4/d8/pscc.shawbiz.ca/html/bunnysredone.jpg";
rename ("/d4/d8/pscc.shawbiz.ca/html/bunnys.jpg",$newfilename);
.....
etc (the rest just shows a web page showing the results)
In the above the renaming of the uploaded file works. It renames
the picture file from 'bunnys.jpg' to 'bunnysredone.jpg'. What I
need, though, is to have the new picture name created from
the picture number that was uploaded (the value of $picnum). So
I replaced the line for $newfilename to be
my $newfilename="/d4/d8/pscc.shawbiz.ca/html/pic".$picnum.".jpg";
With this change, the renaming no longer works. If I comment out
the actual rename line of code and display the value of $newfilename
in the output, it shows exactly what I would have expected it to
be
eg
/d4/d8/pscc.shawbiz.ca/html/pic5.jpg
where the 5 represents the current value for $picnum.
I do not see what I am doing wrong. Can anyone help? When I get
this working I would also like to use the same technique to set
the value of the old name in the rename line.
Thank you.