1

我正在尝试使用 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);
    }
}
4

1 回答 1

1

检查ftp_nb_put函数的示例。您应该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);
于 2013-04-30T08:19:48.957 回答