脚本是:
<?php
$filep = $_FILES['userfile']['tmp_name'];
$ftp_server = $_POST['server'];
$ftp_user_name = $_POST['user'];
$ftp_user_pass = $_POST['password'];
$paths = $_POST['pathserver'];
$name = $_FILES['userfile']['name'];
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_pasv($conn_id, true);
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";
}
$upload = ftp_put($conn_id, $name, $filep, FTP_BINARY, "22");
if (!$upload) {
echo "Error: FTP upload has failed!";
} else {
echo "Good: Uploaded $name to $ftp_server";
}
ftp_close($conn_id);
set_time_limit(300);
?>
当我运行此php
脚本时,会出现警告:
警告:ftp_put():localfile.txt:第26行/Applications/XAMPP/xamppfiles/htdocs/temp/index.php中没有此类文件或目录
getcwd();
表明我在/Applications/XAMPP/xamppfiles/htdocs/temp
目录,在此目录中有文件localfile.txt
有什么问题?
答案 0 :(得分:1)
只需替换:
$upload = ftp_put($conn_id, $name, $filep, FTP_BINARY, "22");
为:
$upload = ftp_put($conn_id, $name, $filep, FTP_BINARY);