Getting around PHP safe mode to write to server. Is it possible?

前端 未结 3 400
长情又很酷
长情又很酷 2021-01-15 05:32

I have got the following problem since the server has safe mode turned on, and directories are being created under different users:

  1. I upload my script to the s
3条回答
  •  死守一世寂寞
    2021-01-15 05:51

    I've used this workaround:

    instead of php mkdir you can create directories by FTP with proper rights.

        function FtpMkdir($path, $newDir) {
           $path = 'mainwebsite_html/'.$path;
           $server='ftp.myserver.com'; // ftp server
           $connection = ftp_connect($server); // connection
    
    
           // login to ftp server
           $user = "user@myserver.com";
           $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
                 ftp_site($connection, "CHMOD 777 $newDir") or die("FTP SITE CMD failed.");
                 return $newDir;
             } else {
               return false;
             }
    
             ftp_close($connection); // close connection
          }
    
      }  
    

提交回复
热议问题