我正在尝试使用html表单上传文件。上传方法是通过FTP到FileZilla服务器。我已成功上传该文件,但似乎只有它的文件扩展名和文件名才能上传。在Windows资源管理器中查看传输的文件时,该文件始终已损坏,并且不显示文件大小。这是我的代码。请帮忙。
include 'Connections/ftpgangconnect.php';
ini_set("upload_max_filesize", "250M");
ini_set("post_max_size", "250M");
if (isset($_POST['upload'])) {
$name = $_FILES['myfile'] ['name'];
$size = $_FILES['myfile'] ['size'];
$type = $_FILES['myfile'] ['type'];
$temp = $_FILES['myfile'] ['tmp_name'];
$error = $_FILES['myfile'] ['error'];
$content = $_FILES['myfile']['content'];
$temp = $_FILES['myfile'] ['tmp_name'];
$name = $_FILES['myfile']['name'];
$dest_file ="/".$name;
// upload the file
$upload = ftp_nb_put($ftp, $dest_file, $temp, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $name";
ftp_close($ftp);
}
}
答案 0 :(得分:1)
检查ftp_nb_put
function的示例。您应该在循环中调用ftp_nb_continue
,直到上传完成:
// upload the file
$upload = ftp_nb_put($ftp, $dest_file, $temp, FTP_BINARY);
while ($upload == FTP_MOREDATA)
{
// Continue uploading...
$upload = ftp_nb_continue($ftp);
}
虽然除非你需要在循环中做任何其他事情,否则使用ftp_nb_put
毫无意义。只需使用简单的ftp_put
代替:
$upload = ftp_put($ftp, $dest_file, $temp, FTP_BINARY);