php - Problem creating folders with right access for file uploade

Discussion in 'PHP' started by chickenhouse, Jun 9, 2008.

  1. #1
    Hi,

    Using php I'm trying to dynamically create a folder and files within the folder.

    If I use mkdir($titlefolder, 0777);

    It doesn't create the folders as I expect. They have rwx r-x r-x access But I need to have at least rwx r-x rwx access as I did before to create the files.

    Because the user is set to apache I can't change the access manually.

    What can I do to get the access I need? Is there some way to sign in to my domain so it will allow me to do what I want?

    Thanks,
    Travis
     
    chickenhouse, Jun 9, 2008 IP
  2. lfhost

    lfhost Peon

    Messages:
    232
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    lfhost, Jun 9, 2008 IP
  3. mehmetm

    mehmetm Well-Known Member

    Messages:
    134
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #3
    hi,

    I guess, php could be run in safe mode.
    once I faced this problem and coded a small script to connect via ftp (in code) and change file/folder permissions.
     
    mehmetm, Jun 9, 2008 IP
  4. chickenhouse

    chickenhouse Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I had a look at chown but it appears to only work for files not directories. I may be wrong.

    The ftp method sounds interesting. Any ideas on how the code would look?

    Thanks,
    Travis
     
    chickenhouse, Jun 9, 2008 IP
  5. mehmetm

    mehmetm Well-Known Member

    Messages:
    134
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #5
    
    <?php
    $ftp_server = 'ftp.yoursite.com';
    $ftp_user_name = 'username';
    $ftp_user_pass = 'password';
    
    $conn_id = ftp_connect($ftp_server); 
    
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 
    
    if ((!$conn_id) || (!$login_result)) { 
    		echo "FTP connection has failed!";
    		echo "Attempted to connect to $ftp_server for user $ftp_user_name"; 
    		exit; 
    } else {
    		echo "Connected to $ftp_server, for user $ftp_user_name<br>";
    }
    
    // the home directory / the folder you change permissions
    $dir = 'httpdocs/permissionforthisfolder';
    
    // try to create the directory $dir
    if (ftp_mkdir($conn_id, $dir)) {
     echo "successfully created $dir<br>";
    } else {
     echo "There was a problem while creating $dir<br>";
    }
    
    if (ftp_chmod($conn_id, 0777, $dir) !== false) {
     echo "$dir chmoded successfully to 777<br>";
    } else {
     echo "could not chmod $dir<br>";
    }
    ?>
    
    PHP:
    regards..
     
    mehmetm, Jun 9, 2008 IP