Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: rename file

by bigup401 (Pilgrim)
on Aug 24, 2020 at 18:08 UTC ( [id://11121048]=note: print w/replies, xml ) Need Help??


in reply to rename file

your dream has come true

use CGI; use CGI::Carp qw ( fatalsToBrowser ); use File::Basename; my $upload_dir = "upload/"; my $query = new CGI; my $filename = $query->param("file"); my $upload_filehandle = $query->upload("file"); $newname = "edddd"; my ($ext) = $filename =~ /([^.]+)$/; my $newfile = "$newname.$ext"; open ( UPLOADFILE, ">$upload_dir/$newfile" ) or die "$!"; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE;

Replies are listed 'Best First'.
Re^2: rename file
by Fletch (Bishop) on Aug 24, 2020 at 22:28 UTC

    You pull in File::Basename, but then manually extract the extension with a regular expression. And probably doesn't do what you mean if $filename doesn't have an extension in it (in which case $newfile will be (effectively) "$newname.$filename" instead).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re^2: rename file
by frank1 (Beadle) on Aug 24, 2020 at 18:13 UTC

    wow this is awesome, this is what i have been looking for, much thanks

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 22:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found