Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 25th, 2001, 11:01 AM
telex4's Avatar
telex4 telex4 is offline
Wacky hack
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Location: London, England
Posts: 512 telex4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 25 m 29 sec
Reputation Power: 8
Unhappy CGI Upload

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)?

Reply With Quote
  #2  
Old July 30th, 2001, 01:53 PM
Art Art is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Belarus
Posts: 1 Art User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Art
Exclamation

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">

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > CGI Upload


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT