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($uploadfi le, 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(!getimag esize($_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($uploadfi le, 444);
if(move_uploade d_file($_FILES['imageloc']['tmp_name'],
$uploadfile)) {
echo 'Upload file success!';
}
else {
echo 'There was a problem uploading your file.<br />';
print_r($_FILES );
} 4 4804
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($uploadfi le, 444);
You need to use the octal format,
example: chmod($uploadfi le, 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($uploadfi le, 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(!getimag esize($_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($uploadfi le, 444); if(move_uploade d_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($uploadfi le, 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($uploadfi le, 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 code doing a file upload...
$upload_result =
|
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 ($file == "none") { echo"Try put an valid file.";
echo"<a href=index.html>back</a>";
}else {
copy($file, "myfile/".$file_name);
unlink($file);...
|
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 them a
caption, storing the caption and filename in a text file. It's a bit
buggy when removing the photos and captions from the file, and also in...
|
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 directory belongs to the PHP-interpreter (UID
33 in my case) and the script doing the file creation and the one
creating the directory belong to 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 specific to
GD.
Here is what I understand so far:
1) a PHP script runs in the webserver user space. In my case, this is
'apache', though I think...
| |
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 really is a chmod problem even though the error message is "no such file or directory", as I'm sure the name and path are right. Even my ftp program...
|
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 online version I'm having problems. Files that
are uploaded can't be seen over FTP client (Total Commander FTP). I
know they are uploaded because if...
|
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 function on the site, which uploads files via POST to
temp folder and then moves it into a folder on the host using php function
move_uploaded_file. Under...
|
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 one help me.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| | |