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~
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~