Downloaded zip files gets corrupt

vps

#1

Hi,
I have a problem when i try to download zip files with comparatively slower internet connections. The file downloaded is corrupt when we try to open it. But if we download the same file with a faster connection, its working fine. I am using php 5.3. What can be the problem?


#2

I think you’ve identified it: slower internet connections, which cause packets to get misplaced along the way (for lack of a longer, more technical explanation).

How big are these zip files?


#3

WHen you change between the slow and fast connections are you also changing the computer they are downloaded to? If so it’s possible the computer connected to the slow connection has a corrupt harddrive and/or malware. It could also be that you are forcing a mode in ftp on the slower connection that you shouldn’t be.

There are a lot of possibilities here. I would think if the checksums didn’t match the ftp would error out. In any case you should ditch ftp in favor of SFTP, there’s not only more security but also better error checking.


#4

Also: Since you mentioned PHP, are there any scripts involved in downloading these files, or are they just coming straight from the web server? (Or are you talking about downloading them using some other method entirely?)


#5

The file size is around 40 MB. I tried the same set of code in another server to download over 175 MB. It works properly. Is there anything I could do to resolve this issue (changing the server settings or something like that) ???


#6
            $yourfile = 'path_to_file';
	$file_name = basename($yourfile);
            header("Content-Type: application/zip");
	header("Content-Disposition: attachment; filename=$file_name");
	header("Content-Length: " . filesize($yourfile));
	readfile($yourfile);

This is the code i am using. I was able to download the file through FTP without any error.


#7

We don’t recommend that you use PHP scripts like this to handle downloads — they can end up using a lot of memory, which can make them unstable, and they prevent downloads from being resumed if they are interrupted. Downloading the file directly over HTTP will be much more reliable.

If you need to implement access control on downloads, you may want to consider storing your downloadable files on DreamObjects, as it supports “signed” temporary URLs for downloads.


#8

Thanks friend… Its working fine now… :slight_smile: