Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can some one please explain to me what does this code do!

Status
Not open for further replies.

fireburner69

Programmer
Aug 22, 2002
108
GR
for($i=0, $j=0; $i < $size ; $i++)
{
$file_upload = $cg->param("image_$i");


if(defined ($file_upload)) {

my $fh = $cg->upload("image_$i");
if(defined $fh)
{
#carp $fh;

($tmp_fh, $tmp_filename) = tempfile();


while(<$fh>) {
print $tmp_fh $_;
}

close($tmp_fh);

$fsize =(-s $fh);

$fh =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$tmp_filename =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$qstring .= "file[name][$j]=$fh&file[size][$j]=$fsize&";
$qstring .= "tmp_name[name][$j]=$tmp_filename&";
$j++;
}
}
}





I can understand that it loops through an array or something!

But what I really want to know is does it create any file!

And if yes How can I set the a path to where to save them!


Thanks in advance!
 
try this:

 if(defined $fh)
        {
            #carp $fh;
$your_path = '/your/path/';
            ($tmp_fh, $tmp_filename) = tempfile();
$tmp_filename = "$your_path"."$tmp_filename";
 
Actually this was easier than I though!

($tmp_fh, $tmp_filename) = tempfile();
must become
($tmp_fh, $tmp_filename) = tempfile(DIR => $dir);

and before that $dir = "../tmp";

so instead of copying the file to the default tmp dir it will be writed into my dir!

Thanks for your time ppl!

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top