100 Web Space
http://forum.100webspace.com/

Perl upload image script trouble
http://forum.100webspace.com/viewtopic.php?f=5&t=42815
Page 1 of 1

Author:  dave79 [ Mon May 18, 2009 8:42 pm ]
Post subject:  Perl upload image script trouble

Hello can anyone help me here?
When i first tried to upload an image using a form i received the error;
"cgi open of tmpfile :read only file system"
I added the line;
$CGITempFile::TMPDIRECTORY = '/tmp';
after being advised from a support ticket.
I now get the error;
No such file or directory at /home/www/yourdomain/cgi-bin/upload.pl line 40.(ive marked this with two ++)
Is this fixable?

Thanks.



#!/usr/bin/perl -wT

use strict;
use CGI;
use CGI::Carp qw ( fatalsToBrowser );
use File::Basename;

$CGI::POST_MAX = 1024 * 5000;
$CGITempFile::TMPDIRECTORY = '/tmp';
my $safe_filename_characters = "a-zA-Z0-9_.-";
my $upload_dir = "/www/yourdomain/uploads";

my $query = new CGI;
my $filename = $query->param("photo");
my $email_address = $query->param("email_address");

if ( !$filename )
{
print $query->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->upload("photo");

open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!"; ++
binmode UPLOADFILE;

while ( <$upload_filehandle> )
{
print UPLOADFILE;
}

close UPLOADFILE;

print $query->header ( );
print <<END_HTML;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Thanks!</title>
<style type="text/css">
img {border: none;}
</style>
</head>
<body>
<p>Thanks for uploading your photo!</p>
<p>Your email address: $email_address</p>
<p>Your photo:</p>
<p><img src="/www/yourdomain/uploads/$filename" alt="Photo" /></p>
</body>
</html>
END_HTML
;

:roll:

Author:  PerlGuy(Tom) [ Sat Jul 18, 2009 6:09 pm ]
Post subject:  Wonderful...

I had a similar upload script that suddenly quit working, (apparently as a
result of relocating 100webspace to new servers some time ago ?).

After fiddling around with things for a while I thought upload programs just
weren't going to be allowed for security reasons or something and gave
up.

I just tried adding the line suggested:


$CGITempFile::TMPDIRECTORY = '/tmp';


Other than having to reset permissions on the upload folder (not sure how
they got changed... possibly also during the move?) It worked like magic!

At first the error message changed from what was posted above to:

-------------
Forbidden
You don't have permission to access /uploads/uploadfile.jpg on this server.
-------------

Thanks for the FORUM!

BTW did the above mentioned problem ever get solved? ("No such file
or directory at...")?

I'm still working on this program. What I would like to do is have a way to
upload ~ and resize ~ photos to a standardized/specified size or sizes.

Here is part of the program that was modified: (and seems, now, to be
working again)

#!/usr/bin/perl
#
######################################
# File Upload
# By Tom...
# This program is free software you can redistribute it
# and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation
# ...yada yada yada
####################################

use strict 'refs';
use CGI::Carp qw/fatalsToBrowser/;
use CGI ':cgi-lib';
use CGI ':cgi';

$CGITempFile::TMPDIRECTORY = '/tmp'; ### new line added.

%name_value = Vars;
$FILEHANDLE = param(path_to_file);

#etc...
-------------------------------

BTW... The list of available Perl Modules page at: http://perlmodules.100ws.com/

Looking for Image::Magick

The page seems to be missing: " The page cannot be displayed
The page you are looking for is currently unavailable. The Web site might be experiencing technical difficulties,..."

Note: Found Image::Magick. It appears to be available on 100WS server.
Found it using Perl Diver. Available here:

http://www.scriptsolutions.com/programs/free/perldiver/

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/