|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
I've been making a simple upload script using the CGI module, and have got to the point where I can process a file and output it to a given filename, like so:
Code:
$filename = "file.tmp";
$file = $cgi->param('file');
$type = $cgi->uploadInfo($file)->{'Content-Type'};
open(FILE,">$filename");
while (<$file>) { print FILE; }
close(FILE);
I then tried turning the $filename that it outputs to into a variable in the form, so the form user can specify the name of the outputted file. First I made an extra input in the form which was the name of the output file wanted. When I put that in like so: Code:
$filename = $cgi->param('filename');
It refuses to save it, cutting out of the program in the line which opens the file. I've double checked and it's not a problem with persmissions. Any ideas? Or reg exps to get the file name perhaps from the full path (when the script is accessed by a browser in Windoze you get the full file path like c:\folder\filename)? |
|
#2
|
|||
|
|||
|
Try this one:
$_=$f{file}; s/\w://; s/([^\/\\]+)$//; $_=$1; s/\.\.+//g; s/\s+//g; $filename=$_; if (!$filename){die('Error! No file')} open FILE,">$filename"; binmode FILE; while ($bytes=read($f{file},$buff,2096)) { print FILE $buff; } close FILE; also you have to insert this line to your form tag: <form method="post" ... enctype="multipart/form-data"> |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > CGI Upload |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|