在PHP与ftp_nb_put上传到FTP的FileZilla服务器上的文件已损坏(File upl

2019-09-01 10:40发布

我试图上传使用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);
    }
}

Answer 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);


文章来源: File uploaded with ftp_nb_put to FileZilla FTP server in PHP is corrupted
标签: php ftp