dongpan1416 2015-06-25 07:56
浏览 43
已采纳

PHP上传脚本损坏文件,文件大小与源文件不同

I am running a php script that is executed on a server when someone clicks a button. The script downloads the file from one server stores the file locally then uploads it to another server.

But the file keeps corrupting somewhere in the middle the end file that is uploaded is always a different size and gets corrupted.

Code Below:

<?php

//Download CSV Script
// connect and login to FTP and download zip
$ftp_server = "URL REDACTED";
$ftp_conn = ftp_connect($ftp_server, 21) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, "USER", "PASS");

// turn passive mode on
ftp_pasv($ftp_conn, true);

$local_file = "feed/establishmentexport.zip";
$server_file = "establishmentexport.zip";

// download server file
if (ftp_get($ftp_conn, $local_file, $server_file, FTP_ASCII))
  {
  echo "Successfully downloaded from X.<br />";
  }
else
  {
  echo "Error downloading feed. Please reload and retry.<br />";
  }

// close connection
ftp_close($ftp_conn);

//End of download.

//FTP UPLOAD SCRIPTS
//Uploading the FTP file EMEA
$ftp_server = "REDACTED";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, "USER", "PASS");
// turn passive mode on
ftp_pasv($ftp_conn, true);

$local_file_u = "feed/establishmentexport.zip";

$server_file_u = "custom/establishmentexport.zip";

// upload file
if (ftp_put($ftp_conn, $server_file_u, $local_file_u, FTP_ASCII))
  {
  echo "Successfully uploaded to EMEA custom folder.<br />";
  }
else
  {
  echo "Error uploading to EMEA custom folder.<br />";
  }

// close connection
ftp_close($ftp_conn);
//End of Uploading the FTP file

?>

展开全部

  • 写回答

1条回答 默认 最新

  • dongmi19720408 2015-06-25 08:11
    关注

    FTP_ASCII is intended to be used when handling text files, I believe you should use FTP_BINARY in order to properly handle your .zip file.

    Replace:

    ftp_get($ftp_conn, $local_file, $server_file, FTP_ASCII)
    

    with:

    ftp_get($ftp_conn, $local_file, $server_file, FTP_BINARY)
    

    And:

    ftp_put($ftp_conn, $server_file_u, $local_file_u, FTP_ASCII)
    

    With:

    ftp_put($ftp_conn, $server_file_u, $local_file_u, FTP_BINARY)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 下面三个文件分别是OFDM波形的数据,我的思路公式和我写的成像算法代码,有没有人能帮我改一改,如何解决?
  • ¥15 Ubuntu打开gazebo模型调不出来,如何解决?
  • ¥100 有chang请一位会arm和dsp的朋友解读一个工程
  • ¥50 求代做一个阿里云百炼的小实验
  • ¥20 DNS服务器所在的国家不同与你的IP地址所在国家
  • ¥15 查询优化:A表100000行,B表2000 行,内存页大小只有20页,运行时3页,设计两个表等值连接的最简单的算法
  • ¥15 led数码显示控制(标签-流程图)
  • ¥20 为什么在复位后出现错误帧
  • ¥15 结果有了,想问一下这个具体怎么输入
  • ¥15 怎么修改鸿蒙app的UI及功能设计
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部