slicks1 slicks1 - 2 years ago 60
Perl Question

Creating a new file with uploaded image file contents perl

I'm a perl newbie. I need to do the following:

my $path=$insfn{'upload'.$i}; // this references the path for the uploaded image file

I need to take the contents of this path (it is an image), and fill it in a new file.

Here is as far as Ive gotten:

my $random = '/path/6dadasd.jpg';
open(my $fh,'>',$random){
print $fh ? how do i get the contents of $path?

I have no idea how to do this in Perl.

Any help would be greatly appreciated.

Answer Source

It sounds like you are asking how to copy a file from the path in $path to the path in $random. You can use File::Copy's copy for that.

use File::Copy qw( copy );

copy($path, $random)
   or die("Can't copy \"$path\" to \"$random\": $!\n");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download