Hi,
I've been spending hours trying to figure out the problem with my upload file program. I have a form where a user presses the 'browse' button , chooses a file on their local directory and then my cgi script downloads it and prints it to a directory. I created this so that people can upload their images.
The form looks like this:
<form action="profile_step4.pl" enctype="multipart/form-data" >
choose file <input type="file" name="photo1">
<input type="submit">
</FORM>
Then, in my "profile_step4.pl" script, I have the following:
#!/usr/local/bin/perl
use CGI;
print "Content-type: text/html\n\n";
&GetAllCookies;
my $userid = $Cookies{userid};
$upload_dir = "/usr/home/tiri/htdocs/upload/"; ## not the real path .
+.. but the path is to my htdocs/upload directory (which already exist
+s)
$mydir .= $upload_dir .$userid ;
`mkdir $mydir`; ## create the directory for this user
print "created the dir $mydir";
$query = new CGI;
$filename = $query->param("photo1");
$upload_filehandle = $query->upload("photo1");
$filename=~ s/.*[\/\\](.*)/$1/;
open (UPLOADFILE, ">$mydir/$filename")|| die $! ;
binmode UPLOADFILE;
while ( <$upload_filehandle> )
{
print UPLOADFILE;
}
close UPLOADFILE;
Any suggestions on why this isn't working? When i run the program, i was able to determine that the program dies on the statement:
$upload_filehandle = $query->upload("photo1");
Why is it dying here? Do I need to set the 'upload' directory with any special permissions?
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.