0

ファイルを FTP サーバーにアップロードしようとしています。ディレクトリはchmode 777でなければならないというifステートメントに引っかかりますが、コードに関数を追加するだけでなく、ftpのすべてのディレクトリを手動でchmode 77にしています。

次に、アップロード プロセスが開始されると作成される .tmp ファイルについてお聞きしたいと思います。それらは FTP にアップロードされていますか? その場合、.mp3 ファイルと一緒に .tmp ファイルへのアクセスも許可する必要がありますか? プロセスで実際にそれらがどのように使用されているかについてはほとんど知らないので、誰かが時間をかけて説明してくれれば非常に役に立ちます.

いくつかの変数の内容:

$upload_path = /htdocs/site2/telemessages/en/Apologies
$_FILES['userfile']['tmp_name'] = /tmp/phpwkfxrW 

ファイルをFTPに渡すために使用しているコードは次のとおりです。

 $ftp_server="***********"; 
 $ftp_user_name="************"; 
 $ftp_user_pass="***********"; 

 // set up basic connection 
 $conn_id = ftp_connect($ftp_server); 

 // login with username and password 
 if(ftp_login($conn_id, $ftp_user_name, $ftp_user_pass)){

// Configuration - Your Options
      $allowed_filetypes = array('.mp3','.tmp'); // These will be the types of file that will pass the validation.
      $max_filesize = 2097152; // Maximum filesize in BYTES (currently 2MB).

      $cutName = substr($_SESSION['dir'], 0, -1); 

      $upload_path = "htdocs/site/telemessages/en/". $_SESSION['dir'];
      echo "upload path: ".$upload_path; // The place the files will be uploaded to (currently a 'files' directory).


   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.

   // Check if the filetype is allowed, if not DIE and inform the user.
   if(!in_array($ext,$allowed_filetypes))
      die('The file you attempted to upload is not allowed.');

   // Now check the filesize, if it is too large then DIE and inform the user.
   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die('The file you attempted to upload is too large.');

   // Check if we can upload to the specified path, if not DIE and inform the user.
   if(!is_writable($upload_path))
      die('You cannot upload to the specified directory, please CHMOD it to 777.');

   // We'll start handling the upload in the next step
   echo"FORCE: ".$_FILES['userfile']['tmp_name'];
       //Upload the file to your specified path.
  $result = move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename);


    if(!$result)
                {
                    return -1;
                }
                else
                {
                    echo $result;
                    //SET PROPER READ PERMISSIONS

                    $result2 = chmod($upload_path, 0777);
                    echo "Result: ".$result2;
                   } 

}else{
echo "login failed";
}

事前に助けてくれてありがとう。

4

1 に答える 1