0

我正在尝试将文件上传到 FTP 服务器。它被 if 语句捕获,该语句指出目录必须是 chmode 777 但是我在 ftp 中手动 chmode 77 并在代码中添加了一个函数。

其次,我想问一下上传过程开始后创建的 .tmp 文件。它们是否上传到 FTP?如果是这样,我是否还需要允许访问 .tmp 文件以及 .mp3 文件?我完全不知道他们在这个过程中的实际用途是什么,所以如果有人能花时间解释一下,那将非常有帮助。

一些变量内容:

$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

0

乍一看,有几件事可能会给您带来麻烦。

$upload_path = /htdocs/site2/telemessages/en/Apologies

我将假设您的代码中实际上有引号。如果不是,则需要修复。

可能性:

  1. Web 服务器无权访问该目录。我知道一些服务器场NFS跨多个服务器使用,并且可能会发生奇怪的许可事情。您可能需要咨询您的服务器公司。
  2. 它可能/htdocs/site2/telemessages/en/Apologies实际上是一个文件而不是一个目录,这可能会导致问题。
  3. Paul Bailey 上面的评论:您可能试图引用系统根目录之外的路径,而它应该不在应用程序根目录之外。因此,他对领先的评论/
于 2013-07-22T16:55:04.203 回答