Gossamer Forum
Home : General : Perl Programming :

File Upload Script.

(Page 2 of 2)
> >
Quote Reply
Re: [Philip_Clark] File Upload Script. In reply to
The CGI::upload error shouldn't be occuring as I removed that code.

This:

open (OUTFILE,">/fileupload/$filename") || die $!;

....needs to be a full path and the directory needs to exist already.

To get rid of the bytesread error try adding

my $bytesread;

....to the top of the code.
Quote Reply
Re: [RedRum] File Upload Script. In reply to
That is the full path. In the Hypermart FAQ it says:

Quote:
What would the full filepath for my directory be?
The filepath to a file in your directory would be simply the relative path to that file. For instance, if your home directory has a sub-directory called "cgi-bin", and cgi-bin has a file in it called "myfile.pl", you would reference "myfile.pl" as "cgi-bin/myfile.pl".

This is the only error I'm getting now:

No such file or directory at /home/fileupload/upload.cgi line 9.


Does the script work on a hosting account of yours Paul?

---------------
Cricket Web - http://www.cricketweb.net
Cricket Web Forum - http://forum.cricketweb.net/
---------------
Quote Reply
Re: [Philip_Clark] File Upload Script. In reply to
Yes that will work when using URL's but not writing to a file. You could try:

open (OUTFILE,">$filename") || die $!;

or

open (OUTFILE,">$ENV{DOCUMENT_ROOT}/fileupload/$filename") || die $!;

Quote:
Does the script work on a hosting account of yours Paul?

Of course Laugh
Quote Reply
Re: [RedRum] File Upload Script. In reply to
YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!YES!

Thanks a lot for that. I decided to try it out on my cricketweb.net hosting account and it works with this code you gave me:

Quote:
#!/usr/bin/perl -w
use CGI qw(:standard);
my $q = new CGI;
my $filename = $q->param("photo");
my $f = $filename;
my $bytesread;
my $email_address = $q->param("email_address");
$filename =~ s/.*[\/\\](.*)/$1/;
open (OUTFILE,">/home/virtual/cricketweb/home/httpd/html/$filename") || die $!;
while ($bytesread=read($f,$buffer,1024)) {
print OUTFILE $buffer;
}
close OUTFILE;
print $q->header();
print qq|
<HTML>
<HEAD>
<TITLE>Thanks!</TITLE>
</HEAD>
<BODY>
<P>Thanks for uploading your photo!</P>
<P>Your email address: $email_address</P>
<P>Your photo:</P> <img src="http://www.cricketweb.net/$filename" border="0">
</BODY> </HTML>
|;

http://www.cricketweb.net/upload.htm

Thanks a lot for your help Paul SmileSmileSmileCoolCool

---------------
Cricket Web - http://www.cricketweb.net
Cricket Web Forum - http://forum.cricketweb.net/
---------------
Quote Reply
Re: [Philip_Clark] File Upload Script. In reply to
Glad you finally got it working lol

Out of interest, I just uploaded an image to your server called yellow.jpg, but it isn't an ordinary image.....see if you can find out why it is different :)
Quote Reply
Re: [RedRum] File Upload Script. In reply to
Quote:
Glad you finally got it working lol

So am I Smile

Quote:
Out of interest, I just uploaded an image to your server called yellow.jpg, but it isn't an ordinary image.....see if you can find out why it is different :)

Hmm... I've scanned it for viruses, opened it in photoshop, looked at it for about 2-3 minutes... LOL what the heck is it Laugh

---------------
Cricket Web - http://www.cricketweb.net
Cricket Web Forum - http://forum.cricketweb.net/
---------------
Quote Reply
Re: [Philip_Clark] File Upload Script. In reply to
Hehe.......it has another file hidden within the image......not a virus, just a text file, but it could have been a virus if I had wanted.


Quote Reply
Re: [RedRum] File Upload Script. In reply to
Oh ok - how did you do that?

Norton Antivirus would have picked it up wouldn't it?

---------------
Cricket Web - http://www.cricketweb.net
Cricket Web Forum - http://forum.cricketweb.net/
---------------
Quote Reply
Re: [Philip_Clark] File Upload Script. In reply to
Yeah Norton would have picked up the virus.

The attached file has the Links2 add.cgi file hidden inside it........


Quote Reply
Re: [RedRum] File Upload Script. In reply to
Clever Wink

---------------
Cricket Web - http://www.cricketweb.net
Cricket Web Forum - http://forum.cricketweb.net/
---------------
Quote Reply
Re: [RedRum] File Upload Script. In reply to
What would the code be to only allow *.jpg or *.gif files to be uploaded via the script?



---------------
Cricket Web - http://www.cricketweb.net
Cricket Web Forum - http://forum.cricketweb.net/
---------------
Quote Reply
Re: [Philip_Clark] File Upload Script. In reply to
$filename =~ /\.(gif|jpg)$/i or &some_error;
Quote Reply
Re: [RedRum] File Upload Script. In reply to
Thanks Paul. I'll try it out and let you know Smile

---------------
Cricket Web - http://www.cricketweb.net
Cricket Web Forum - http://forum.cricketweb.net/
---------------
> >