Hi, I want Php script to download files.

Thanks in advance,
Revathy.

Comments

nevets’s picture

What are you trying to do? Core comes with the upload module and if using CCK there is the filefield module.

sanjanaa’s picture

Thank you for your reply nevets.

I uploaded my files into server through FTP. I used this php code to download that file.

$file="pactus.zip";
header("Content-type: application/octet-stream");
header("Content-Type: application/zip");
header("Content-Type: application/jpg");
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=\"$file\"");
header("Content-Transfer-Encoding: binary");
readfile("pactus.zip");

Using this code, I can able to download upto 4MB size files only. If my download exceed 4MB files, it downloads that file and if i tried to open the file it shows some error and it could not be opened.

For example:

1) If I download pdf files, then it shows while opening it,

"There was an error opening this document. The file is damaged and could not be repaired"

2) If I download zipped file, then it shows
"No archives to extract".

How can I solve this problem?

Thanks,
Revathy.

mm167’s picture

check the file size after download. I guess u haven't successfully downloaded the whole file due to memory issue.

u may need a professional readfile() function (then the FREE readfile()) to handle large files.

good day.

sanjanaa’s picture

Thank you mm. Yes my download file size is very small than the whole file. Ya i doesn't download fully. But I don't know what is professional readfile(). Can you please give any reference link for that?

Thanks,
Revathy.

amelia.rahman’s picture

Hi, I just recently use drupal 7 and got same problem with you. Did you find any solution?
The file perfectly fine if I only opened it in browser via link, but always corrupted when trying to automatically download it. So, I guess there is nothing to do with the file?
Thanks.