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

File upload via web form 1

Status
Not open for further replies.

grebo

Programmer
Sep 21, 1998
38
US
I've been trying to do a file upload via a web form so that a user can post a file to a web directory from a web form. I've banged my head against javascript for a while and no luck (I think due to security). I've seen plain form submissions to a directory via a web form using perl, can I also use it to post a file to the same directory (much like a bulliten board)? Any help would be most appreciated as my perl skills are not up to par for web programming...<br>
<br>
Thanks,<br>
-Eric<br>

 
Eric-<br>
<br>
Well, being new to Perl, and presently wtill working on honing my JavaScript, dHTML, and now HTML 5.0 skills I can't help you much with the Perl part of this. BUT I can give you the HTML that you'll need for it:<br>
(inside your &lt;form&gt; and &lt;/form&gt; tags put the following where you'd like to allow users to do their file upload):<br>
&lt;input type=file&gt;<br>
(and if you really want to make things a little easier on your clients, e-mail me,and I can design you a JavaScript to check thier http file uploading capabilities)<br>
<br>
-Robherc
 
I'm also a newbie to Perl, but in the CGI module (use CGI), there's a File upload function which may be able to do what you are after.<br>
I haven't tried it myself, but the documentation should provide an example or two (man perlcgi or man CGI, I can't remember which)<br>
<br>
Milamber
 
Eric,

I have been working with perl for sometime now,

What you will need is a form with a <input type='file' name='blah'> in it and this submitting to a cgi where you need to get the value of the input field and run this command:

while ($size = read($upload_file,$buffer,1024)) {
print FILE $buffer;
$total_size = $size;
}

The variable $upload_file is the value of the input field from the previous form, you may find that you have some problems with this but just make sure that your permissions are set so that the httpd user can write to the directory you are trying to write to. BTW FILE is a filehandle for the location that you are trying to write to.

If you want more info drop us an email.
 
There are two FAQs on this topic at faq219_406 and faq219_352. The first uses CGI.pm and the second uses cgi-lib.pl or CGI_Lite.pm.

'hope this helps...


keep the rudder amid ship and beware the odd typo
 
I really thought those two faq ids were going to show up as links. Since they did not, just click the FAQ tab at the top of the Perl forum front page and look for the FAQs on uploading files. I think they are number 7, maybe.

HTH


keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top