Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just a note: however you will write it, <strong>don't</strong> save it in a place accessible from your web-server.</p> <p>And now to the point: below is a script which I was using for some time for photo-uploading. It might need some tweaking, but should show you the way.</p> <p>As the image isnt uploaded to web-accesible directory, we then have separate process checking it, resizing, putting a watermark and placing it where it can be accessed.</p> <pre><code> #!/usr/bin/perl -wT use strict; use CGI; use CGI::Carp qw ( fatalsToBrowser ); use File::Basename; $CGI::POST_MAX = 1024 * 5000; my $safe_filename_characters = "a-zA-Z0-9_.-"; my $upload_dir = "/home/www/upload"; my $query = new CGI; my $filename = $query-&gt;param("photo"); my $email_address = $query-&gt;param("email_address"); if ( !$filename ) { print $query-&gt;header ( ); print "There was a problem uploading your photo (try a smaller file)."; exit; } my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' ); $filename = $name . $extension; $filename =~ tr/ /_/; $filename =~ s/[^$safe_filename_characters]//g; if ( $filename =~ /^([$safe_filename_characters]+)$/ ) { $filename = $1; } else { die "Filename contains invalid characters"; } my $upload_filehandle = $query-&gt;upload("photo"); open ( UPLOADFILE, "&gt;$upload_dir/$filename" ) or die "$!"; binmode UPLOADFILE; while ( &lt;$upload_filehandle&gt; ) { print UPLOADFILE; } close UPLOADFILE; print $query-&gt;header ( ); print &lt;&lt;END_HTML; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Thanks!&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;p&gt;Thanks for uploading your photo!&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; END_HTML </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload