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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Upload ?s 1

Status
Not open for further replies.

JimJx

Technical User
Joined
Feb 16, 2001
Messages
202
Location
US
I am probably doing something stupid here, but hope that someone can shed some light on this for me....

Trying to do a file upload and I want the local file name to be used as the remote name.

For example if the local name is test.txt, the remote name should be test.txt.

What I am getting, is the file I am uploading is a very simple file that contains a single line that states "This is a test file."

When the file is saved, it is saved as "This is a test file"

Can anyone point me in the right direction?

Thanks for reading,
Jim

Code:
if ($input{'UPLOAD'}) {
$dir = '/home/users/web/b2578/pow.royridgeway/htdocs/Roy/';
$filename =~ s/.*[\/\\](.*)/$1/;
my $upload_filehandle = "$filename";

open UPLOADFILE, ">$dir/$filename, 0755";
binmode UPLOADFILE;
   while ( <$upload_filehandle> )
   {
       print UPLOADFILE;
   }
close UPLOADFILE;
}
 
Can you show us more of your code? Where did $filename come from?

If you're using the CGI module, there are two different methods involved with getting upload file data:

Code:
$q->param ("filename"); # "C:/My Documents/test.txt"
$q->upload ("filename"); # "This is a test file"

where "filename" is the name of your <input type="file"> field on the uploading web page.

-------------
Cuvou.com | The NEW Kirsle.net
 
For various reasons, I have to go old school with this one.....

Code:
$filename = $input{'UPLOAD'};

And that is giving me the contents of the file, instead of saving the file itself.....

 
What code are you using to get $input? Are you using cgi_lib.pl or some home-made script? If it's a home-made script, you should be able to make some minor modifications to save the filename in a separate variable when you find it, and then go ahead and make $input{'UPLOAD'} be the uploaded file's data.

-------------
Cuvou.com | The NEW Kirsle.net
 
A quick Google search I did for "cgi_lib.pl" returned this page as its first result:

"Demonstration of using CGI_LIB.pl for HTTP File Upload."

I tested it and got...

Code:
$CGI{'UploadedFile'}->{'Content-Type'}	application/zip

$CGI{'UploadedFile'}->{'Contents'} ...binary data...

$CGI{'UploadedFile'}->{'filename'}	RiveScript-1.03.zip
$CGI{'UploadedFile'}->{'name'}	UploadedFile

-------------
Cuvou.com | The NEW Kirsle.net
 
>> For various reasons, I have to go old school with this one.....

can you explain why?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
The biggest reason is economic, on my part. This is a web site I am trying to add a few features too. the rest of the site is coded this way. No CGI, etc. I was told that they want the site to be consistent and if I wanted to go to CGI, I would have to recode the whole site, on my dime.

I think that to go through the whole site and recode everything will take a lot more time than I am willing to invest.......
 
Unless we're talking about hundreds of different CGI files, it wouldn't be that hard to modify them...

Just copy-and-paste a section of code to the top of every file in place of what's already there (the parts that define %input)...

Code:
use CGI;
my $q = CGI->new;
our %input = ();
foreach my $what ($cgi->param) {
   my $is = $cgi->param($what);
   $input{$what} = $is;
}

and then $input{'UPLOAD'} and all other form fields would be populated the same as they are now.

Anyway, did our responses help solve your initial problem?

-------------
Cuvou.com | The NEW Kirsle.net
 
First, thanks to everyone for their help.

I am going to use CGI on this after a LONG talk with the client this morning.

So, I grabbed the FAQ did a copy/paste and now am getting another error.

Short Read: wanted 861, got 0


Anyone encountered this before?

Thanks again,
Jim
 
The CGI module supports the common cgi-lib functions for backwards compatability.


it's not well documented in the CGI documentation but if you look in the CGI modules source code you will find:

Code:
':cgi-lib' => [qw/ReadParse PrintHeader HtmlTop HtmlBot SplitParam Vars/],

so you can use them by importing the :cgi-lib functions or call them as fully qualified functions:

CGI::ReadParse
CGI::PrintHeader
etc
etc

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
First, sorry it took so long for me to get back to everyone.

The suggestions helped greatly, thank you to everyone that took the time to respond.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top