473,326 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 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 4783
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: kafooey | last post by:
Hi all, I've been digging around on the newsgroups and the web for a possible answer for this problem, but have so far come up with nothing so thought I would ask here... I have the following...
2
by: silveira neto | last post by:
I got a php script that makes a upload to my server. But it actualy don't works. I'm working on Kurumin Linux 2.13, Apache 1.3.26 and PHP4. The source (it handles an string gotten in a form): if...
2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
4
by: pdav | last post by:
Hi! Is there any solution to create a directory with one script with mkdir(), and then write a file (or move an uploaded file) in this directory with another script? The problem is, that the...
6
by: jonathanmcdougall | last post by:
I have read many posts on this subject and found no satisfying answer. I am creating a file on the server via a PHP script. The file is created using GD (imagejpeg()), though I don't think it is...
3
by: webhead | last post by:
I have a web where users can upload photos, but they want to also be able to delete them. The directory can have chmod changes but it won't let me chmod the files and unlink them. I'm assuming it...
7
by: luigi7up | last post by:
Weird problem I have, really :) I wrote a script that uploads files to /user_upload/ directory. On localhost version of my site everything works just fine. I mean files are uploaded well. With...
4
by: Tony B | last post by:
I've moved an existing site (which I didn't write) from a apache/php/mysql host under windows to a linux apache/php/mysql host. I've sorted out most problems except one. There is an upload...
4
by: Dev | last post by:
Hello All, i am unable to upload file using following code: chmod("upload", 0777); move_uploaded_file($_FILES, "./upload/". $_FILES); chmod("upload", 0755); what wrong in this code any...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.