PDA

View Full Version : UPload Permissions Issue


progressweb
01-04-2007, 08:32 PM
We are using a cgi script to upload images to a server. The upload works like a charm but the server is saving the file as chmod 600 instead of 644 so its of no use to anyone viewing the image from the web. We have tried to edit the save function to chmod upon upload but its not working. See upload function below:

sub uploading{ ########################################### UPLOADING
&check_user;
$imagesizeKB = $imagesize*1000;
use CGI qw/:standard :html3/;
$file = param('upload');
if (!$file) {error("No File Was Uploaded","Upload Error")}
$file =~ m!([^/:\\]*)$!;$file_name=$1;
$file_location = $imagespath.$file_name;
open (SAVE,">$file_location") || error("Could Not Create File<br>$file_name","Upload Error");
binmode (SAVE);
while ($size = read($file,$data,1024)) {
print SAVE $data;
$total_size += $size;
}
close SAVE;chmod(0644,"$file_name");
unless ($total_size > 0) {unlink($file_location);error("The File Contained No Content","Upload Error")}
if($total_size > $imagesizeKB){unlink($file_location);error("The File Size Exceeded $imagesize KB<P>The File Upload Was Rejected","Upload Error")}
print "Content-type: text/html\n\n";
print qq~

EZS
01-14-2007, 06:13 PM
This can be fixed by adding a line:

`umask xxx`;

to the start of your script (underneath the path to Perl). xxx is a numeric code but you should ask your host support what it should be.

KevinADC
01-14-2007, 07:06 PM
perl has a umask function, there is really no need to shell out to set the umask. You can try this:

umask(000);

before trying to chmod the files.

EZS
01-14-2007, 07:23 PM
perl has a umask function, there is really no need to shell out to set the umask. You can try this:

umask(000);

before trying to chmod the files.

You are right Kevin on this one, Kevin. Just wanted to get him away from the chmod part :thumbsup: