所以ftp_put表示文件已成功上传,但是如果我检查服务器没有找到文件,我已经检查了chmod权限,它们是777。 这是我上传文件时收到的消息:
conectd as a9408563@server23.000webhost.com Het bestand是succesvol geupload(该文件已成功上传)。连接关闭
这是我的代码:
<?php
$ftp_server = "xxxx";
$ftp_username = "xxx";
$ftp_password = "exxx";
$uploadedfile = $_FILES["uploadedfile"]["tmp_name"];
$destination_path = "/public_html/files";
//setup of connection
$conn_id = ftp_connect($ftp_server) or die("could not connect to $ftp_server");
//login
if(@ftp_login($conn_id, $ftp_username, $ftp_password))
{
echo "conectd as $ftp_username@$ftp_server\n";
}
else {
echo "could not connect as $ftp_username\n";
}
ftp_pasv($conn_id, true);
/*
$remote_file_path = " /home/a9408563/public_html/files".$uploadedfile;
ftp_put($conn_id, $remote_file_path, $uploadedfile,
FTP_BINARY);
ftp_chdir($conn_id, '/public_html/files/');
ftp_put($conn_id, $destination_path.$_FILES["uploadedfile"]["name"], $_FILES['uploadedfile']['tmp_name'], FTP_BINARY );
*/
if (ftp_nb_put($conn_id, $destination_path.$_FILES["uploadedfile"]["name"], $_FILES['uploadedfile']['tmp_name'], FTP_BINARY))
{
echo "Het bestand is succesvol geupload.";
}
else
{
echo "Het bestand is niet geupload.";
}
ftp_close($conn_id);
echo "\n\nconnection closed";
?>
答案 0 :(得分:0)
ftp_nb_put
比ftp_put
更灵活,但检查结果也更复杂。一个简单的if(ftp_nb_put())
电话是不够的。
尝试使用ftp_put()
,或了解如何检查ftp_nb_put
的成功in the manual:
// Initiate the Upload
$ret = ftp_nb_put($my_connection, "test.remote", "test.local", FTP_BINARY);
while ($ret == FTP_MOREDATA) {
// Do whatever you want
echo ".";
// Continue uploading...
$ret = ftp_nb_continue($my_connection);
}
if ($ret != FTP_FINISHED) {
echo "There was an error uploading the file...";
exit(1);
}
&#13;