By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,325 Members | 1,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,325 IT Pros & Developers. It's quick & easy.

File upload problem, Chmod

P: n/a
Hi i'm having a problem with file permissions of upload, they appear to
be being set to only readable by the administrator, so anyone browsing
the site gets a 403 forbidden error when they try and view the image.

I've tried adding the following line: -

chmod($uploadfile, 444);

and also a few variations on it but to no avail.

Could someone please point me in the right direction?

Thanks in advance.

Ian

Script below: -

if($_FILES['imageloc']['name'] == '') {
echo 'The Small image remains the same or default<br />';
}
elseif($_FILES['imageloc']['size'] > $MAX_FILE_SIZE) {
echo 'The small image you selected is too large<br />';
}
elseif(!getimagesize($_FILES['imageloc']['tmp_name'])) {
echo 'The small image you selected is not a valid image file<br
/>';
}
else {
$uploaddir = '/web/html/images/'; // remember the trailing slash!
$uploadfile = $uploaddir. $_FILES['imageloc']['name'];
chmod($uploadfile, 444);
if(move_uploaded_file($_FILES['imageloc']['tmp_name'],
$uploadfile)) {

echo 'Upload file success!';
}
else {
echo 'There was a problem uploading your file.<br />';
print_r($_FILES);
}

Aug 19 '05 #1
Share this Question
Share on Google+
4 Replies

P: n/a
Ian N wrote:
Hi i'm having a problem with file permissions of upload, they appear to
be being set to only readable by the administrator, so anyone browsing
the site gets a 403 forbidden error when they try and view the image.

I've tried adding the following line: -

chmod($uploadfile, 444);


You need to use the octal format,
example: chmod($uploadfile, 0444);

and I think that 0755 would be more appropriate.
Aug 19 '05 #2

P: n/a
Ian N wrote:
Hi i'm having a problem with file permissions of upload, they appear to
be being set to only readable by the administrator, so anyone browsing
the site gets a 403 forbidden error when they try and view the image.

I've tried adding the following line: -

chmod($uploadfile, 444);

and also a few variations on it but to no avail.

Could someone please point me in the right direction?

Thanks in advance.

Ian

Script below: -

if($_FILES['imageloc']['name'] == '') {
echo 'The Small image remains the same or default<br />';
}
elseif($_FILES['imageloc']['size'] > $MAX_FILE_SIZE) {
echo 'The small image you selected is too large<br />';
}
elseif(!getimagesize($_FILES['imageloc']['tmp_name'])) {
echo 'The small image you selected is not a valid image file<br
/>';
}
else {
$uploaddir = '/web/html/images/'; // remember the trailing slash!
$uploadfile = $uploaddir. $_FILES['imageloc']['name'];
chmod($uploadfile, 444);
if(move_uploaded_file($_FILES['imageloc']['tmp_name'],
$uploadfile)) {

echo 'Upload file success!';
}
else {
echo 'There was a problem uploading your file.<br />';
print_r($_FILES);
}

Hi,

Maybe it helps if you first move the file, then chmod it.
Now you are trying to chmod the file while it is in the temp-directory.

It has its TEMPname, not the filename

So 2 solutions:

1)
$uploadfile = $uploaddir. $_FILES['imageloc']['tmp_name'];
chmod($uploadfile, 444);

2) first move it to the path and name you like, then chmod it (with the
right name).

Regards,
Erwin Moller

Aug 19 '05 #3

P: n/a
Erwin Moller wrote:


Hi,

Maybe it helps if you first move the file, then chmod it.
Now you are trying to chmod the file while it is in the temp-directory.

It has its TEMPname, not the filename

So 2 solutions:

1)
$uploadfile = $uploaddir. $_FILES['imageloc']['tmp_name'];
chmod($uploadfile, 444);

2) first move it to the path and name you like, then chmod it (with the
right name).

Regards,
Erwin Moller


Hi, I made a mistake, because it did misread your code.

The solution is:
1) first move the file to a new path/name
Then chmod it.

If you try to chmod it in the tmp-directory, you should use the tmp_name.

Regards,
Erwin Moller
Aug 19 '05 #4

P: n/a
Cheers!

Got it sorted, thanks for your help

Ian

Aug 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.