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: Intermediate:
problem with RENAME function..

 



$0.05$
Novice

Jul 22, 2002, 12:01 PM

Post #1 of 2 (1658 views)
problem with RENAME function.. Can't Post

ok, what im doing, is uploading an image file to a directory. After the image is uploaded, i wish to rename it, so here is the code that im using


Code
  

if (lc($filename) =~ /\.jpg|\.gif|\.jpeg|\.png/){
print "file accepted";
open UPLOADFILE, ">$upload_dir/$filename";
while ( <$upload_filehandle> ) {
print UPLOADFILE;
}
close UPLOADFILE;

($t, $handle) = split(/\./, $filename);

rename("$upload_dir/$filename","$upload_dir/$newfilename");



Paul
Enthusiast

Jul 22, 2002, 7:02 PM

Post #2 of 2 (1653 views)
Re: [$0.05$] problem with RENAME function.. [In reply to] Can't Post

>>
if (lc($filename) =~ /\.jpg|\.gif|\.jpeg|\.png/){
<<

Could be:

if ($filename =~ /\.(?:jpe?g|gif|png)$/i){

You might want to add:

binmode UPLOADFILE;

...just below your open() so the image doesn't crap out on Windoze :)

>>
($t, $handle) = split(/\./, $filename);
<<

What if the file path contains another period?

What is the actual problem with the rename?....you can use $! to find out if it is just not renaming....

rename("$upload_dir/$filename","$upload_dir/$newfilename") or die $!;

 
 


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

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