supm Posted February 27, 2011 Share Posted February 27, 2011 Hi, I'm trying to implement the following code that I found at http://www.actionscript.org/forums/showthread.php3?t=83105 $fileToDownload = "path/to/your_file.zip"; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Type: application/zip"); // you can put here MIME type of your file header("Content-Disposition: attachment; filename=\"" . basename($fileToDownload) . "\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($fileToDownload)); set_time_limit(0); readfile("$fileToDownload"); This is a script that supposedly masks the actual URL paths of downloadable files so they can't be as easily redistributed. I have searched elsewhere on the web and have found many variations of this script. Unfortunately, none of these scripts worked properly. The files concerned are ZIP files. When accessing a ZIP file via one of the scripts concerned, it seems to download fine, as the file name and size is retained upon completion of download. However, when attempting to open or extract the ZIP file, error messages pop up noting that the ZIP file is either invalid or empty. (I have tried echoing the actual path to confirm that the download is coming from the correct location, and it is.) Contrarily, when I download a ZIP file by navigating to the actual URL, the file is extractable and not declared empty. I have tried on various browsers, including the latest versions of Firefox and Chrome. Any ideas? Is it perhaps an issue with the hosting service? Quote Link to comment https://forums.phpfreaks.com/topic/229024-hidden-download-url-invalid-zip/ Share on other sites More sharing options...
supm Posted March 1, 2011 Author Share Posted March 1, 2011 Update: I opened the ZIP file in Notepad++ and discovered that HTML was mixed in. In fact, it seems that most if not all of the HTML of the webpage that feeds the ZIP file content somehow got mixed into the ZIP file itself. Quote Link to comment https://forums.phpfreaks.com/topic/229024-hidden-download-url-invalid-zip/#findComment-1181125 Share on other sites More sharing options...
supm Posted March 1, 2011 Author Share Posted March 1, 2011 I got rid of any HTML on the page and the downloads now seem valid and extractable. Solved for now. Quote Link to comment https://forums.phpfreaks.com/topic/229024-hidden-download-url-invalid-zip/#findComment-1181128 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.