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);
} 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.
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
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
Cheers!
Got it sorted, thanks for your help
Ian This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
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)...
|
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....
|
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...
| | |