简体   繁体   English

PHP FTP_GET下载失真的.jpg图像

[英]PHP FTP_GET downloading distorted .jpg images

I have a scenario in which I need to use FTP_GET to recursively download and organize a fair amount of images (usually, 2-3k ~1mb .jpg's at a time). 我有一种情况,在这种情况下,我需要使用FTP_GET递归下载和组织大量的图像(通常一次2-3k〜1mb .jpg)。

I've built the entire system and never once actually opened a downloaded image, as the file size is an exact match and no errors or issues had sprung up until now. 我已经构建了整个系统,并且从未真正打开过下载的图像,因为文件大小是完全匹配的,并且到目前为止没有出现错误或问题。 (D'oh!) (哦!)

However, as the project is nearing completion...I've noticed that ALL the downloaded images are heavily distorted (but obviously aren't on the remote server). 但是,随着项目即将完成...我注意到所有下载的图像都严重失真(但显然不在远程服务器上)。

I'll provide any additional information you may need, but here's what I think is relevant. 我会提供您可能需要的其他信息,但这是我认为相关的信息。

A new connection is opened, then a single image is downloaded, then the connection is closed. 打开一个新的连接,然后下载一个图像,然后关闭该连接。 I know it would be better to download multiple files per connection, but due to certain circumstance this is an easier option. 我知道最好为每个连接下载多个文件,但是由于某些情况,这是一个更简单的选择。 Is it possible I'm somehow closing the connection too early? 我是否可能以某种方式过早关闭连接? (even though the filesize matches?) I'm using the regular, "blocking" ftp_get as opposed to ftp_nb_get...so, I wouldn't suspect this as an issue, but figured that I would mention it anyway. (即使文件大小匹配?)我使用的是常规的“阻止” ftp_get,而不是ftp_nb_get ...所以,我不会怀疑这是一个问题,但我想无论如何我都会提到它。

if ( ftp_get($ftp, $local_file, $server_file, FTP_BINARY)) {

The above is the relevant code, which is wrapped in a for each loop. 上面是相关的代码,在每个循环中都包装了。 The if statement does eval to true. if语句确实为true。

Any ideas? 有任何想法吗? Thanks in advance for any help! 在此先感谢您的帮助!

Here's a link to both the original and distorted images, if this helps. 如果有帮助,这是原始图像和失真图像的链接。 http://imgur.com/3ePSmBj,0vV5pwA#0 http://imgur.com/3ePSmBj,0vV5pwA#0

Stupid me! 愚蠢的我! I had put FTP_ASCII instead of FTP_BINARY. 我放了FTP_ASCII而不是FTP_BINARY。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM