Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

uploading file to server

Status
Not open for further replies.

LookingBeyond99

Programmer
Jul 2, 2001
18
0
0
US
My question is pretty simple. I'm uploading a file from a user and trying to upload it to a server. However for some reason I can't open up a new file to store the information.

open(FILE, ">$filepath");
print FILE $CGI{'upload'}->{'Contents'};
close (FILE) || die "Error close filehandle: $!";

$filepath has the path on the server which includes the name of the file to to be created. For some reason this only works if a file is already there and replaces that file with the new contents. But if the file doesn't already exist then it returns an error. I thought the > means that if a file didnt already exist it would create it.

I also have tried adding this line after the open
chmod 0666, '$filepath';

but it doesn't seem to help but I think I'm doing something dumb.

 
The problem probably has to do with whether the userid the web server runs under has permission to create a file in that directory. Try this to see what the error is:
Code:
open(FILE, ">$filepath") || oops("Can't open file $filepath\n$@";
And include this little subroutine somewhere:
Code:
sub oops {
   my($err) = @_;
   print &quot;<p>ERROR: $err</p></body></html>&quot;;
   exit 0;
}
That's pretty much the same oops routine that goBoating wrote in a different thread. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top