I am developing a website which requires images to be uploaded through a CMS my the company owner only.
I have a upload.php(file browse option) which links to upload_file.php which works fine except when the files upload they are stored with a permission of 0600 and cannot for the life of me figure out how to change this automatically when the files upload.
If I transfer the files through the FTP manually then the permission is correct (0644) but not when uploaded through my CMS.
I have the following code for the upload_file:
Code: Select all
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/JPG")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 200000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("../images/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"../images/" . $_FILES["file"]["name"]);
echo "Stored in: " . "../images/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>Code: Select all
chmod("../images/" . $_FILES["file"]["name"], 0644);
I can get the chmod to work if i manually enter the file name like:
Code: Select all
<?php chmod ("images/photo1.jpg", 0644); ?>I have also tried changing the permissions when the files are being retrieved but that doesnt work either: (storing the filename in the database manually.) then retriveing it.
photos.php
Code: Select all
$result = @mysql_query('SELECT * FROM tbl_images');
if (!$result) {
exit('<p>Error Performing Query: ' . mysql_error() . '</p>');
}
while ($row = mysql_fetch_array($result)) {
chmod("images/' . $row['filename'] . '",0644);
Any help would be greatly appreciated
Thank you