我正在尝试将文件上传到 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";
}
感谢您提前提供任何帮助。