CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
My script won't work

 



Pro_4
User

Apr 17, 2001, 5:19 PM

Post #1 of 9 (515 views)
My script won't work Can't Post

I dont know why but everytime i try to use this script on my site it gives me all these weird errors. I html script works fine and all the variables are the same. Also i chmod the script to the right number and made sure i Ftped (i guess thats how you would say it) using Asci. Maybe someone will be able to tell me what is going on here. I attached the script to the post.
Thanks :)

¿HELP?


Pro_4
User

Apr 18, 2001, 6:54 PM

Post #2 of 9 (506 views)
Re: My script won't work [In reply to] Can't Post

The error i always when i try to upload something is a 404 File Not Found error. The html script points directly at the cgi script so i dont see why it wouldnt find it. I dont get it :(

Always add fun to Perl
$fun = "fun"; $perl = "Perl";
print " Always add $fun to $perl"; die;


wickedxter
User

Apr 18, 2001, 10:21 PM

Post #3 of 9 (504 views)
Re: My script won't work [In reply to] Can't Post

try messing around with this

$upload = param('upload');

$name = "$upload";
$name =~ s!^.*(\\|/)!!;
$file = param('upload');
$file =~ m!([^/:\\]*)$!;
$short_name = $1;
open (SAVE,">$UploadDir/$short_name");
binmode(SAVE);
while ($size = read($file,$data,1024)){
print SAVE $data;
$total_size += $size;
}
close SAVE;



localfilmmaker
stranger

Apr 19, 2001, 12:32 PM

Post #4 of 9 (498 views)
Re: My script won't work [In reply to] Can't Post

A 404 error, eh? Well, my guess would be a permissions problem. Either the file is not readable by the web server, or the directory that it's in isn't readable by the web server. Or it could be that you misspelled the filename or path to the cgi script in your HTML page. That one gets me all the time. Stupid typos! Also, make sure that your form is set like this:

<form action="upload.cgi" method="POST" enctype="multipart/form-data">

The script won't upload a thing, if you don't set the form's enctype to multipart.

-localfilmmaker
Spencer Christensen
spencer@mecworks.com


Pro_4
User

Apr 19, 2001, 12:57 PM

Post #5 of 9 (497 views)
Re: My script won't work [In reply to] Can't Post

Ok thanks i will try that :)

Always add fun to Perl
$fun = "fun"; $perl = "Perl";
print " Always add $fun to $perl"; die;


Pro_4
User

Apr 19, 2001, 2:45 PM

Post #6 of 9 (492 views)
Re: My script won't work [In reply to] Can't Post

Lol. I figured out why i was getting a 404 error. I was giving the full direction to the script "etow.virtualave.net/cgi-bin/upload1.cgi" when it needed to be just "/cgi-bin/upload1.cgi" that is why it couldnt find it. But when i tried it again it gave me a 500 error and was told this

Debugging Information:

Premature end of script headers: /data1/va/etow/cgi-bin/attempt.pl

what does that mean?

Always add fun to Perl
$fun = "fun"; $perl = "Perl";
print " Always add $fun to $perl"; die;


Pro_4
User

Apr 19, 2001, 3:29 PM

Post #7 of 9 (490 views)
Progress !!! [In reply to] Can't Post

Finally the script initializes and goes all the way through. But now i got a lot of errors in my cgi error log.
Use of uninitialized value at upload1.cgi line 11.
print on closed filehandle main::SAVE at upload1.cgi line 14.
print on closed filehandle main::SAVE at upload1.cgi line 14.
print on closed filehandle main::SAVE at upload1.cgi line 14.
print on closed filehandle main::SAVE at upload1.cgi line 14.
print on closed filehandle main::SAVE at upload1.cgi line 14.
print on closed filehandle main::SAVE at upload1.cgi line 14.
print on closed filehandle main::SAVE at upload1.cgi line 14.
print on closed filehandle main::SAVE at upload1.cgi line 14.

Now why it gave me that last part 8 times in a row i dont know but it did. I am going to attach the exact script i am using right now that i updated. :) well atleast it is saying it is doing something now.

Always add fun to Perl
$fun = "fun"; $perl = "Perl";
print " Always add $fun to $perl"; die;


localfilmmaker
stranger

Apr 23, 2001, 2:10 PM

Post #8 of 9 (471 views)
Re: Progress !!! [In reply to] Can't Post

Ok, now we're gettinh somewhere. I looked at your html and your perl, and I think I have found where things are breaking down.

In your HTML page you have:
<INPUT TYPE="FILE" NAME="file">

But in your cgi script you have:
$upload = param('upload');

This is looking for a cgi field with the name "upload", but there isn't one in your form, yours is named "file". So, all you would have to do is change your files so that they are both talking about the same cgi field. This is also why you got all those error messages.

From your cgi script:
$upload = param('upload'); #---This parameter doesn't exists, so $upload is an empty string ""
$name = "$upload"; # $name is now an empty string
$name =~ s!^.*(\\|/)!!; # still an empty string
$file = param('upload'); # Same thing as with $upload, $file is an empty string
$file =~ m!([^/:\\]*)$!; # This won't match anything, because $file is empty
$short_name = $1; # There was no match above, so $1 is undef, therefore $short_name is undef
open (SAVE,"/$UploadDir/$short_name"); #WARNING- using $short_name when it doesn't have
# a value. Therefore, this open statement will fail and the file handle SAVE won't be open
binmode(SAVE);
while ($size = read($file,$data,1024)){
print SAVE $data; # This will give an error every time it tries to write to SAVE, because
# SAVE isn't open
$total_size += $size;
}

-localfilmmaker
Spencer Christensen
spencer@mecworks.com


Pro_4
User

Apr 23, 2001, 6:24 PM

Post #9 of 9 (466 views)
YEAH!!!! [In reply to] Can't Post

Yes, it finally worked. :) Thank you so much i thought i was going to pull out all of my hair because it wouldnt work. I really appreciate it.

Always add fun to Perl
$fun = "fun"; $perl = "Perl";
print " Always add $fun to $perl"; die;

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives