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

Uploading image via browser ????

Status
Not open for further replies.

Vesku

Programmer
Jun 7, 2000
19
0
0
FI
Hi !<br><br>Is there a very simple way to upload .jpg or .gif images via IE and NS browser to selected directory ???<br><br>...and if is, how can i make that ?<br><br>Please help me !!!
 
This is functional but to simple.&nbsp;&nbsp;Allowing users to upload stuff is a little dangerous.&nbsp;&nbsp;You should probably pay attention to file types.&nbsp;&nbsp;See the docuemtation for CGI.pm for more.<br><br>#!/usr/local/bin/perl<br># author:&nbsp;&nbsp;<br># date:&nbsp;&nbsp;&nbsp;&nbsp;<br># Purpose: figure out how to use CGI.pm to upload file via <br># the browser.<br>##############################################################<br>use CGI;<br>$thisCGI = '/path/to/your/file/upload';<font color=red># change for your situation</font><br><br>$query = new CGI;<br>print $query-&gt;header,$query-&gt;start_html(-title=&gt;&quot;UPLOAD THIS&quot;);<br>print $query -&gt;start_multipart_form('POST',&quot;$thisCGI&quot;);<br><br>print &quot;Enter or Browse to the file you would like to upload.&lt;BR&gt;\n&quot;;<br>print $query-&gt;filefield(-name=&gt;'fileID',<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; -size=&gt;50,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -maxlength=&gt;80);<br><br>my $fileID = $query-&gt;param('fileID');<br>@pathName = split(/\\/,$fileID);<br>$newFile = '/where/you/want/to/put/the/file/';<font color=red># change for your situation</font><br>$newFile .= pop(@pathName);<br><br>if ($fileID)<br>&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp; open(OPF,&quot;&gt;$newFile&quot;) ¦¦ &showError(&quot;Failed to open OPF, $!&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp; while ($bytesread=read($fileID,$buffer,2048)) { print OPF &quot;$buffer&quot;; }<br>&nbsp;&nbsp;&nbsp;&nbsp; $type = $query-&gt;uploadInfo($fileID)-&gt;{'Content-Type'};<br>&nbsp;&nbsp;&nbsp;&nbsp; print &quot;&lt;BR&gt;Upload of $newFile of type $type Successful&lt;BR&gt;\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>print '&lt;BR&gt;',$query-&gt;submit('doWhat','uploadMe');<br>print $query-&gt;end_form;<br>print $query-&gt;end_html;<br><br>sub showError<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;my @error = @_;<br>&nbsp;&nbsp;&nbsp;&nbsp;print &quot;&lt;CENTER&gt;&lt;font color=\&quot;\#ff4500\&quot;&gt;Fatal ERROR - @error&lt;/font&gt;&lt;BR&gt;\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;print &quot;Submission aborted - your data was not saved!!&lt;BR&gt;\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;print &quot;Please use the BACK button to return to the previous page&lt;BR&gt;\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;print &quot;and correct the error.&lt;BR&gt;&lt;/CENTER&gt;\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;print $query-&gt;end_form,$query-&gt;end_html;<br>&nbsp;&nbsp;&nbsp;&nbsp;exit;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br> <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top