472,103 Members | 1,066 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,103 software developers and data experts.

File upload problem, Chmod

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
4 4695
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
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
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
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.

Similar topics

3 posts views Thread by kafooey | last post: by
2 posts views Thread by silveira neto | last post: by
2 posts views Thread by matt | last post: by
4 posts views Thread by pdav | last post: by
6 posts views Thread by jonathanmcdougall | last post: by
3 posts views Thread by webhead | last post: by
7 posts views Thread by luigi7up | last post: by
4 posts views Thread by Tony B | last post: by
4 posts views Thread by Dev | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.