Jump to content


Photo

permission question


  • Please log in to reply
7 replies to this topic

#1 adamordna

adamordna
  • New Members
  • Pip
  • Newbie
  • 5 posts
  • Locationhawaii

Posted 01 September 2006 - 06:49 AM

I have the following code....

if(isset($_POST['addnew']))
{
$id='entry_'.$_POST['rid'];
$path= '/var/www/vhosts/domainname.com/httpdocs/files/'.$id;
$fullpath= $path;
if(!is_dir($fullpath))
{
mkdir($fullpath, 0777);
}

if(is_dir($fullpath))
{
if ($_FILES['file_upld']['tmp_name'])
{
$temp_name = $_FILES['file_upld']['tmp_name'];
$filename = $_FILES['file_upld']['name'];
$dir = $fullpath.'/';
move_uploaded_file($temp_name,$dir.$filename);
chmod($dir.$filename, 0777);
}

}
}
It all works fine problem is it asigns the ownership to apache and i can't delete or download the files once they are in there, i can read, edit , etc.. but not download or delete... also it appears that the permissions are really 755 not 777..but i think that's common?
I have never grown out of the infantile belief that the universe was made for me to suck...

#2 logu

logu
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 01 September 2006 - 07:12 AM


using phpinfo() check
the safe mode in your php.ini is on or off
these kind of problem may accur when its 'ON'

#3 adamordna

adamordna
  • New Members
  • Pip
  • Newbie
  • 5 posts
  • Locationhawaii

Posted 01 September 2006 - 07:16 AM

safe_mode is ...Off
thanks......
I have never grown out of the infantile belief that the universe was made for me to suck...

#4 adamordna

adamordna
  • New Members
  • Pip
  • Newbie
  • 5 posts
  • Locationhawaii

Posted 03 September 2006 - 09:12 PM

I still haven't found a solution for this?
I have never grown out of the infantile belief that the universe was made for me to suck...

#5 hobojjr

hobojjr
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 03 September 2006 - 10:31 PM

I have the same problem.

#6 adamordna

adamordna
  • New Members
  • Pip
  • Newbie
  • 5 posts
  • Locationhawaii

Posted 03 September 2006 - 11:05 PM

bummer.. i really need to get this issue resolved..let me know if you find out anything..thanks in advance
I have never grown out of the infantile belief that the universe was made for me to suck...

#7 hobojjr

hobojjr
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 03 September 2006 - 11:34 PM

here did some reading  lol

from comments at http://ca.php.net/mkdir
" Han Van den Hoof
09-Nov-2003 01:28
If you're on a shared *nix server, a directory created through mkdir() will not be assigned to you, but to the user that your host's server or php process is running under, usually 'nobody', 'apache' or 'httpd'.

In practice, this means that you can create directories, even add files to them, but you can't delete the directory or its contents nor change permissions.

It is therefore advised to create directories through PHP's FTP API. Here's a function I wrote:

<?php
// create directory through FTP connection
function FtpMkdir($path, $newDir) {
 
      $server='ftp.yourserver.com'; // ftp server
      $connection = ftp_connect($server); // connection
 

      // login to ftp server
      $user = "me";
      $pass = "password";
      $result = ftp_login($connection, $user, $pass);

  // check if connection was made
    if ((!$connection) || (!$result)) {
      return false;
      exit();
      } else {
        ftp_chdir($connection, $path); // go to destination dir
      if(ftp_mkdir($connection,$newDir)) { // create directory
          return $newDir;
      } else {
          return false;     
      }
  ftp_close($conn_id); // close connection
  }

}
?>

Hope this comes in handy for someone.
"

#8 adamordna

adamordna
  • New Members
  • Pip
  • Newbie
  • 5 posts
  • Locationhawaii

Posted 04 September 2006 - 03:25 AM

so using that i have...
function FtpMkdir($FTPpath, $id)
{
$server='www.myserver.com'; // ftp server
      $connection = ftp_connect($server); // connection
// login to ftp server
      $user = "user";
      $pass = "pass";
      $result = ftp_login($connection, $user, $pass);
// check if connection was made
    if ((!$connection) || (!$result))
    {
      return false;
      exit();
      }
      else
      {
      ftp_chdir($connection, $FTPpath); // go to destination dir
      if(ftp_mkdir($connection,$id))
      { // create directory
      return $id;
      }
      else
      {
        return false;     
        }
  ftp_close($conn_id); // close connection
  }
    }
############################################
if(isset($_POST['addnew']))
{
$FTPpath= '/httpdocs/compFiles/';
$id='entry_'.$_POST['rid']; //new dir name
$path= '/var/www/vhosts/mydomain.com/httpdocs/compFiles/'.$id;

if(!is_dir($path)) 
{
FtpMkdir($FTPpath, $id); // make dir 
}
if(is_dir($path))  // directory already  exists
{
chmod($path, 0707);
if ($_FILES['file_upld']['tmp_name']) //upload file
{
$temp_name = $_FILES['file_upld']['tmp_name'];
$filename = $_FILES['file_upld']['name'];
$dir = $path.'/';
move_uploaded_file($temp_name,$dir.$filename);
chmod($dir.$filename, 0707);
$success = "<font color=\"green\">Your file was uploaded successfully</font>";
}
}
}

Which now creates a directory that at least doesn't belong to apache, has permissions  755
but doesn't upload the file ,unless i change the permissions to 707 , and chmod($path, 0707);
nor chmod($dir.$filename, 0707); seem to be working...

I have never grown out of the infantile belief that the universe was made for me to suck...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users