Click to See Complete Forum and Search --> : Upload file CGI not working


hitekmom
06-28-2003, 04:48 PM
I used the following "Upload file" from this site and with no success. According to the script I need the "some-script.cgi" file. Am I suppose to substitute this cgi for a common cgi? If so where can I find it?

Here's the part of the "upload file" that I found here pointing to a cgi file that I obviously needed:

<form method=post name=upform action="/cgi-bin/some-script.cgi" enctype="multipart/form-data">
<input type=file name=uploadfile>

Thx for any help that anyone can give.

- HiTekMom

P.S. The simple file upload capabilities that I want is just like the one included in this format to a "Attach file

pyro
06-28-2003, 05:41 PM
Sounds like you don't have any script at all, so take a look at http://cgi.resourceindex.com/Programs_and_Scripts/Perl/File_Management/File_Uploading/

hitekmom
06-28-2003, 06:26 PM
I went to the site you listed, thank you very much! I installed one of the scripts to my cgi-bin and replaced the "some-script.cgi" with the scripted I download. I tried the script in the .html file given and with the .htm file I already had and received this msg on both times:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@monicar.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Maybe this is a problem I need to contact my host provider with?

Thx again, you are a doll.

pyro
06-28-2003, 06:30 PM
Did you CHMOD the files, or probably more important, the directory that you are trying to upload to. The script probably has some documentation telling you what these need to be CHMODed to. Probably 777 or 766

hitekmom
06-28-2003, 11:31 PM
Okay! Here's what I've done --

1) I've changed the CHMOD to 755 (according to my host server) for both the file and the cgi-bin directory where the upload.cgi file resides
2) I changed the first line in the .cgi file to reflect the location which is /usr/bin/perl

And now I'm getting a "500 Internet Server Error" (Its that better than 404 :-). My .htm file doesn't have to be in the same directory if I used the absolute path in the .cgi file does it?

Thx for your patience!

- HiTekMom

pyro
06-28-2003, 11:33 PM
Is 755 what the documentation for the script said? 755 does not allow the script to write to folders (thus not allowing users to upload files). Do you have a link to the script you used?

hitekmom
06-28-2003, 11:41 PM
Here's the link to the script:
http://swankyscripts.com/scripts.php?page=perluploader
Unfortunately the free script doesn't come with docs. The paying script does.

When I tried to set the CHMOD to 766 for the .cgi file resets itself to 733 and when CHMOD to 777 it resets to 717

Is this a host problem?

- HiTekMom

pyro
06-28-2003, 11:55 PM
You need to CHMOD the directory that the script trys to upload to. The directory set it this line:

open (UPLOAD, ">../path/to/upload/dirctory") || Error ();

Set that to 777

hitekmom
06-29-2003, 12:20 AM
I'm sorry. I'm sure it's me - - I just don't get it. But, I'm not giving in. It's new, but I love it. Here's what I did:

I changed the
open (UPLOAD, ">../path/to/upload/dirctory") || Error ();

to read
open (UPLOAD, ">../home/client") || Error ();

then I tried to CHMOD that directory (the dir where the files are to reside after uploading) to 777 but it didn't take. The dir CHMOD to 717 automatically.

Is this a permission problem bwt the Host and myself?

If not, should I try a different script?

I really appreciate your time and expertise!!!!!

hitekmom
06-29-2003, 12:32 AM
Pyro,

I may have been using the wrong directory on my server. As I reread the server docs there is a dir that allows external anonymous ftp access to up/download.

I'm going to move my .htm file there and see if I can CHMOD that directory to 777.

You're the best!!!!!!!!!!!!

jeffmott
06-29-2003, 01:11 AM
Add this to the program codeuse CGI::Carp 'fatalsToBrowser';This will give you the real error. Knowing what the problem is helps tremendously in finding the solution. ;)

hitekmom
06-29-2003, 01:21 AM
Well, I've tried the host server ftp:../public_html/incoming but that didn't work.

Pyro do you agree to Jeff's post?

No offense Jeff. I'm trying alot of stuff. I'm sure I'll try the fatalsToBrowser -- I'm just not familiar with what the outcome will be.

hitekmom
06-29-2003, 07:35 AM
Okay! I determine.

Jeff: Do I place the line anywhere in the .cgi script?

jeffmott
06-29-2003, 07:42 AM
Jeff: Do I place the line anywhere in the .cgi script?Yes, it can go just about anywhere. But is customarily put near the top.I'm just not familiar with what the outcome will beIt will replace the "500 Internal Server Error" message with the error message generated by Perl.

hitekmom
06-29-2003, 07:54 AM
Good morning Jeff:

I place the line in the top but am still getting 500 error.

First, my first line points to the ../cgibin should it point to /usr/bin/perl

2nd, I cannot CHMOD the dir, to be uploaded to, to 777 or 776, when I do this it automatically changes to 733 or 717, it's currently CHMOD to 755

hitekmom
06-29-2003, 07:58 AM
Here's what the top part of my .cgi looks like:

#!/home/mrascent/public_html/cgi-bin -wT
use CGI::Carp 'fatalsToBrowser';
use strict;
use CGI ':standard:';

print "Content-type: text/html\n\n";

my $file = param ('uploadfile');
my $info = uploadInfo ($file);
my $type = $info -> {'Content-Type'};

if ($file) {
open (UPLOAD, ">/home/mrascent/public_ftp/incoming") || Error ();
my ($data, $length, $chunk);
while($chunk = read ($file, $data, 1024)) {
print UPLOAD $data;

Here's what my .htm looks like:

<form action="/cgi-bin/uploading.cgi" method=POST ENCTYPE="multipart/form-data" target=infofr>

nkaisare
06-29-2003, 08:20 AM
1. The first line should be the path to your perl program. In your shell, type "which perl". This will give you the location of perl. The first line would probably read "#/usr/bin/perl"

2. The permissions for the cgi-bin directory should be 755.

3. If the permissions for your "some-script.cgi" is 755, then the permissions for the directory you store the uploaded file should be 777 or 766.
Alternatively, you may set permissions for "some-script.cgi" to be 4755. In that case you may have permissions for the upload directory to be 7** (744 or 700 is also fine).

jeffmott
06-29-2003, 08:23 AM
should it point to /usr/bin/perlYes, this is the path to the Perl interpreter on your server.#!/usr/bin/perlit's currently CHMOD to 755This is actually the permissions you want.use CGI ':standard:';You have an extra colon in there. Should be use CGI ':standard';

hitekmom
06-29-2003, 08:33 AM
Okay!!! Now we're getting somewhere.

I have not yet set the permissions as you stated (I will) I was so excited about finally getting something other than 500 error I wanted you to see it:

Software error:

syntax error at uploading.cgi line 20, near ") {"
syntax error at uploading.cgi line 29, near "}"
Execution of uploading.cgi aborted due to compilation errors.

hitekmom
06-29-2003, 08:44 AM
When I try to set permission to the dir "../incoming" to 766 it set itself to 733

jeffmott
06-29-2003, 08:51 AM
Software error:
syntax error at...This is what the fatalsToBrowser did for ya. Otherwise it would have been another 500 error.line 20The portion of the script you posted doesn't go up this far. We'll need to see more.When I try to set permission to the dir "../incoming" to 766 it set itself to 733Some servers limit only the cgi-bin to be executable. But this is fine because the upload directory doesn't need to be executable, only writable to the owner. So you'll want to set permissions for this directory to 711.

hitekmom
06-29-2003, 08:58 AM
I believe this is line 20:

if($length > 51200) {

and this is line 29:

} else {

Thank you for the fatalstoBrowser!!!!!

hitekmom
06-29-2003, 09:08 AM
Gotta run for a couple of hours.
I'll be right back, so please continue to post. Here's the other half of the .cgi script (including lines 20 & 29):


print UPLOAD $data;

$length += $chunk

if($length > 51200) {
print "That file is too big. The limit is 50k.";
exit;
}
}
close (UPLOAD);

print "<p>You uploaded <b>$file</b> which had a MUME type of <b>$type</b>.";

} else {
print "No file was chosen.";
}

sub Error {
print "Couldn't open temporary file: $!";
exit;
}

jeffmott
06-29-2003, 09:15 AM
Originally posted by jeffmott
So you'll want to set permissions for this directory to 711Sorry, my bad. It should actually be 744.I try to set permission to 766Also, there is no such permission as 766.

The first digit represents the owner (you), the second digit groups, and the third all users (you generally don't worry about group when dealing with a Web server, just give it the same value as all users).

Each digit is made up of three bits. Each bit acting as a switch. The first bit represents read permission, the second bit write permission, and the third execute.

We always want the owner to have full permissions, so we set all three bits, 111. When you treat these three bits as an integer in binary and convert it to decimal we get 7. So our first digit is 7, giving the owner full permissions.

For group and all users, we want to give them read but not execute or write permissions (note that a Web user does not actually execute a CGI program. their browser sends an HTTP request and the Web server running as owner, which already has full permissions, executes the program and returns the output). So we set the read bit to 1, and write and execute to 0 for both the groups (second digit) and all users (third digit). 100, which in decimal equals 4.

Sooooo, we get a final permission value of 744.$length += $chunkThis is where the real problem is. The semi-colon is missing here.

nkaisare
06-29-2003, 10:01 AM
Originally posted by jeffmott
Also, there is no such permission as 766.
I thought 6 = read+write.

Using permissions 4755 for your cgi file makes cgi file "behave" like the owner. So, it will read/write/execute according to permissions set for owner.

Probably its not recommended to set permission 4755 for the cgi. But if you dont, then the ownership of the file saved by the upload.cgi is set to "www", so you will not be able to edit it.

Am I making sense? I am not sure about implications of doing this. This (chmod 4755) is what the server guy suggested when some of my scripts were not working.

pyro
06-29-2003, 10:10 AM
Originally posted by hitekmom
Pyro do you agree to Jeff's post?When it comes to Perl, Jeff's knowledge is FAR greater than my own. I personally use PHP...

Originally posted by hitekmom
Also, there is no such permission as 766.Yes, it is equal to Read, Write, and Execute for Owner; Read and Write for Group; and Read and Write for Other. or -rwxrw-rw-

jeffmott
06-29-2003, 12:31 PM
Also, there is no such permission as 766

I thought 6 = read+write
Yes, it is equal to Read, Write, and Execute for Owner; Read and Write for Group; and Read and Write for Other. or -rwxrw-rw-You know... I try and tell my self sleep is a good thing... I just never seem to listen! :rolleyes:

hitekmom
06-29-2003, 12:48 PM
Jeff: Sleep is a good thing, just not right now:o

Thank you for the CHMOD lesson, I understood. But, there are 3 dir and/or files I need to CHMOD:
1.) .cgi file
2.) where the .cgi file resides
3.) the dir where the files will be uploaded to

Is this correct? If so, then
1.) 755
2.) 755
3.) 744

Getting back to my line 20 & line 29 error msg:

You said, quote:"
-------------------------------------------------------------------
$length += $chunk
-------------------------------------------------------------------

This is where the real problem is. The semi-colon is missing here. "

But did not indicate where the semi-colon should be. Also, I don't think this is line #20 or 29.

Thx

hitekmom
06-29-2003, 01:38 PM
Don't stop now guys! We're getting soooo close. Here's the error msg I'm getting. If we can just take care of these, I'm sure we'll get to the problem:

Software error:

syntax error at uploading.cgi line 20, near "){"
syntax error at uploading.cgi line 29, near "}"
Execution of uploading.cgi aborted due to compilation errors.


- Thx I'll make you dinner!

pyro
06-29-2003, 02:14 PM
Originally posted by jeffmott
You know... I try and tell my self sleep is a good thing... I just never seem to listen! :rolleyes: lol... Yeah, looking at the times of your posts, you must not have gotten too much.. :)

hitekmom
06-29-2003, 02:17 PM
I'm determined!!

Can you please look at my syntex error for lines 20 and 29 please

[line 20] if($length > 51200){
print "That file is too big. The limit is 50k.";
exit;
}
}
close (UPLOAD);

print "<p>You uploaded <b>$file</b> which had a MUME type of <b>$type</b>.";

line 29} else {

jeffmott
06-29-2003, 02:39 PM
But, there are 3 dir and/or files I need to CHMOD:
1.) .cgi file
2.) where the .cgi file resides
3.) the dir where the files will be uploaded to

Is this correct? If so, then
1.) 755
2.) 755
3.) 744Those should all work fine.But did not indicate where the semi-colon should be.In Perl a semi-colon terminates a statement. So that line should read $length += $chunk;Also, I don't think this is line #20 or 29.White space is insignificant in Perl. So you could write$length
+=

$chunk


;And it would be valid. Not very readable, but valid. A statement may also be followed by a modifier. For instance, you could write a single lined if statement this wayprint 'Happy' if $happy;Since there is a missing semi-colon on the line I mentioned earlier, the if statement that begins a couple lines down is read as a modifier.$length += $chunk

if($length > 51200) {So for the italicized section, Perl sees no problem. But an if used as a modifier cannot start a block, so it's not until Perl sees the opening brace "{" that it realizes something is wrong.

I hope I explained the well.lol... Yeah, looking at the times of your posts, you must not have gotten too much.. 26 hours and counting :)

hitekmom
06-29-2003, 02:40 PM
After playing with line 20, I'm no longer getting the error msg for that line:

Here's the original line 20:
if($length > 51200){

Here's what I did to line 20:
if($length > 51200)
I also had to remove the } from line 23

I'm no longer getting any syntex errors for line 23.

None on to line 29.

What do you think?

jeffmott
06-29-2003, 02:43 PM
Here's what I did to line 20:
if($length > 51200)
I also had to remove the } from line 23Well... you may have supressed the error message, but the problem isn't necessarily fixed. We posted about the same time. Read my other post to see what I mean.

hitekmom
06-29-2003, 02:49 PM
Oh no!!! Perl doesn't recognize white spaces and I was counting (well MSWord anyway) blank lines as a line number.

Well, I must redo what I've done and start from your last post.

Thx so much

hitekmom
06-29-2003, 03:06 PM
Yes, your explanation makes sense (kinda scary).

I've changed the syntax back and added the ; to $chunk
ran 3 of the .html files I've been testing with the .cgi script and this is what I get:

File #1: No file was chosen.
File #2: Couldn't open temporary file: No such file or directory
File #3: Couldn't open temporary file: No such file or directory

These files were all tested in Netscape 6.1 only.
I prefer to use file #1 because it allows the user to chose up to 8 files and I copied this code from my server "Upload file(s)" directory

Are we getting close?