Skip to content

Instantly share code, notes, and snippets.

@shelling
Created May 31, 2009 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shelling/120909 to your computer and use it in GitHub Desktop.
Save shelling/120909 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use CGI qw(:all);
print header(-charset => "utf-8");
start_html;
print h2("image list");
print p(
a {
href => "image-upload.pl",
style => "text-decoration: none;"
},
"upload new image",
);
for (glob("photos/*")) {
print a { href => $_ }, $_;
print br;
}
print end_html;
#!/usr/bin/env perl
# simple image uploading using cgi
use 5.010;
use CGI qw(:all :cgi-lib);
use Data::Dumper;
print header(-charset => "utf-8"),
start_html(-title => "image-upload.pl");
print h2("image upload");
print p("test cgi for image uploading"),
p (
a { href => "image-list.pl", style => "text-decoration: none;" }, "list image"
);
print start_multipart_form,
filefield(-name => "uploaded_data", -default => "start value"),
submit(-name => "upload", -value => "submit"),
end_form;
$filename = param("uploaded_data");
if ($filename =~ m/(png|gif|jpg)$/) {
open IMAGE, " > photos/$filename" or die;
while (<$filename>) {
print IMAGE $_;
}
print img { src => "photos/$filename" };
} else {
print "uploaded data is not available image format" if $filename;
}
print end_html();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment