Hi Monks!
I am having a bug problem on this part of my code where I am uploading a PDF file from a html form and checking in the directory where all my PDF(s) will be to see if I have a duplicated file name in there, if its a “YES” I am trying to rename the file been uploaded using a random number, also to avoid further duplication of file names I am trying to rename any submitted file with a unique name, using the random number variable as well.
I can not get the code to rename the file am I missing something because I am dealing with a binary file, or its just something I can't not see any more, thanks for the help!!!
Here is part of the code.
...code here
#Random Number
my $n_range = 100000;
my $n_minimum = 1;
my $random_num = int(rand($n_range)) + $n_minimum;
#@ext will have my valid extension, I am looking for .pdf
my $file_in = param('manual'); # This parameter is from the upload for
+m.
if ($file_in){
foreach $ext (@ext){
if (grep /$ext$/i,$file_in){
$match=1;
}
}
if ($match){
opendir(DIRCHCK, $dir) or die $!;
while ($check_file = readdir(DIRCHCK)) {
#chomp $check_file;
$check_file=~ s/\s+$//;
# Only files
next unless (-f "$dir$check_file");
# Find files ending in .pdf
next unless ($check_file =~ m/\.pdf$/);
$file_in =~ s/.*[\/\\](.*)/$1/;
if($check_file=~/\b$file_in\b/gi){
rename "$file_in", "$random_num"."$file_in" or warn "
+Couldn't rename file: $!\n";
}
} #end while
closedir(DIRCHCK);
#call upload
&upload;
}else {
&go_bk;
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.