使用ftp_nb_put上传到FileZilla FTP服务器的文件已损坏 [英] File uploaded with ftp_nb_put to FileZilla FTP server in PHP is corrupted

查看:227
本文介绍了使用ftp_nb_put上传到FileZilla FTP服务器的文件已损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用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 = ftp_nb_put($ ftp,$ dest_file,$ temp,FTP_BINARY);

//检查上传状态
if(!$ upload){
echoFTP upload has failed!;
} else {
echoUploaded $ name;
ftp_close($ ftp);


$ / code $ / pre

解决方案

检查 ftp_nb_put 功能。您应该在循环中调用 ftp_nb_continue ,直到上传完成:

  //上传文件
$ upload = ftp_nb_put($ ftp,$ dest_file,$ temp,FTP_BINARY);

while($ upload == FTP_MOREDATA)
{
//继续上传...
$ upload = ftp_nb_continue($ ftp);

b



虽然除非需要在循环中执行其他任何操作,它毫无意义地使用 ftp_nb_put 。只需使用简单的 ftp_put

  $ upload = ftp_put($ ftp,$ dest_file,$ temp,FTP_BINARY); 


I'm trying to upload a file using an html form. The upload method is via FTP to a FileZilla server. I have successfully uploaded the file but it seem like only it's file extension and file name are the ones that get uploaded. The file is always corrupted and doesn't display it's file size when viewing the transferred file in windows explorer. This is my code. Please help.

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

Check the examples for the ftp_nb_put function. You should be calling the ftp_nb_continue in a loop, until the upload is finished:

// upload the file
$upload = ftp_nb_put($ftp, $dest_file, $temp, FTP_BINARY);

while ($upload == FTP_MOREDATA)
{
   // Continue uploading...
   $upload = ftp_nb_continue($ftp);
}


Though unless you need to do anything else in the loop, its pointless to use ftp_nb_put. Just use a simple ftp_put instead:

$upload = ftp_put($ftp, $dest_file, $temp, FTP_BINARY);

这篇关于使用ftp_nb_put上传到FileZilla FTP服务器的文件已损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆