Hello Monks,

This code is executed when uploading images. There are two fields per image upload(1)FULL SIZE (1)THUMB SIZE. These need to be uploaded into seperate directories.

Currently the code refers to only one directory that is written to $Photo_Dir Which holds full size IMAGES .
I am trying to write to a second directory $Thumb_Dir which should hold thumbnail IMAGES

The file prefix for the thumbnail images is "th_".

Thanks,
Still being new to perl I am still learning. Can anyone shed some light on how to go about doing this.

Cal
use CGI; $max_num_files ||= 1; $Photo_Dir ||= $ENV{'DOCUMENT_ROOT'}; undef @bad_extensions if @good_extensions; for(my $a = 1; $a <= $max_num_files; $a++) { my $req = new CGI; if($req->param("FILE$a")) { my $file = $req->param("FILE$a"); my $filename = $file; $filename =~ s/^.*(\\|\/)//; $filename =~ s/ +/\_/g; #For IE $filename =~ s/ +/\_/g; #For Opera $filename =~ s/\"//g; my $proceed_type = 0; if(@good_extensions) { foreach(@good_extensions) { my $ext = $_; $ext =~ s/\.//g; if($filename =~ /\.$ext$/) { $proceed_type = 1; last; } } unless($proceed_type) { push(@was_not_good_type, $filename); } } elsif(@bad_extensions) { $proceed_type = 1; foreach(@bad_extensions) { my $ext = $_; $ext =~ s/\.//g; if($filename =~ /\.$ext$/) { $proceed_type = 0; last; } } unless($proceed_type) { push(@was_a_bad_type, $filename); } } else { $proceed_type = 1; } if(($auto_rename == 2) && (-e "$Photo_Dir/$filename")) { $proceed_type = 0; push(@rejected, $filename); } if($proceed_type) { if((-e "$Photo_Dir/$filename") && ($auto_rename == 1)) { my $pick_new_name = 1; my $fore_num = 1; $filename =~ /^(.+)\.([^\.]+)$/; my $front = $1; my $ext = $2; while($pick_new_name) { my $test_name = $front . $fore_num . '.' . $ext; unless(-e "$Photo_Dir/$test_name") { $pick_new_name = 0; $filename = $test_name; } $fore_num++; } } elsif((-e "$Photo_Dir/$filename") && ($auto_rename == 2)) { next; } if(open(OUTFILE, ">$Photo_Dir/$filename")) { while (my $bytesread = read($file, my $buffer, 1024)) { print OUTFILE $buffer; } close (OUTFILE); if($max_size) { if((-s "$Photo_Dir/$filename") > ($max_size * 1024)) { push(@was_too_big, $filename); unlink("$Photo_Dir/$filename"); } else { push(@file_did_save, $filename); } } else { push(@file_did_save, $filename); } } else { push(@did_not_save, $filename); } } }

In reply to Adding directory to code by cal

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.