Dear PerlMonks,
I'm having troubles with a CGI to upload images to my site, I've tried lots of ways to solve it... but none worked!
the code i'm using is something like that:
#!/usr/bin/perl
use CGI;
use CGI::Carp 'fatalsToBrowser';
CGI::ReadParse(*in);
my $homeurl = 'http://joao.warp.psi.br';
my $imagedir = '/www/joao/images';
my ($s,$m,$h,$mday,$mon,$year,$w,$y) = gmtime(time);
my $id = $year.$mon.$mday;
# save thumbnail
my $thumb = &FileUpload($in{iddt});
open(MAKETHUMB,">$imagedir/$idt.gif")
or die("Could not save $idt.gif");
print MAKETHUMB $thumb;
close(MAKETHUMB);
# save image 'idd'
my $img = &FileUpload($in{idd});
open(MAKE,">$imagedir/$id.gif")
or die("Could not save $id.gif");
print MAKE $img;
close(MAKE);
# the images are mine!
my @files = glob("$id*.gif");
chown 'joao','fodas',@files;
# upload file (used here to upload images)
sub FileUpload {
my ($formfield) = shift;
my ($filename,$filesize,$filedata);
# load query handle
$query = $in{CGI};
if ($filename = $query->param($formfield)) {
my $tmp = $/;
undef($/);
$filedata = <$filename>;
$filesize = length($filedata);
$/ = $tmp;
}
# find what the trails look like and get the
# true file name without the garbage
if ($filename =~ m/[\\\/\:]/gi) {
$filename =~ s/[\\\/\:]/\//g;
my @tmp = split(/\//,$filename);
$filename = pop(@tmp);
}
return($filedata);
}
well, with this i've got the following:
- the thumbnail file is not created;
- The second image is created but nothing is printed, the image remains with 0k, and is owned by wwwrun;
Because of that, i ask:
why were my images not uploaded?
and why my 'chown' is not working properly?
Can anyone help me? please!
Thank you!!
PS: Oh, and i'm using 'enctype="multipart/formdata"' in my form... and the fields are with the correct names...
#!/jpsama/bin/perl -w
$tks = `mount`;
$jpsama = $! if $!;
print $jpsama;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.