Jump to content

CHMOD Major Help needed.... permission from 0600 to 064


marshmellows_17

Recommended Posts

Hello

 

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:

 
<?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";
  }
?> 

 

I have tried variations of the following:

 

 
chmod("../images/" . $_FILES["file"]["name"], 0644); 

 

Nothing seems to work, I either break the whole server folder with the images in it or I receive an error message.

 

I can get the chmod to work if i manually enter the file name like:

 

<?php chmod ("images/photo1.jpg", 0644); ?> 

 

but thats not much use when the company owner is uploading files as it would require the code to be added every time

 

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

 

 

$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);

 

I really am starting to get desperate as the client would like his website working properly but I am rather new to all this and this is just one thing I cannot seem to get my head around.

 

Any help would be greatly appreciated

 

Thank you

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.