Download and Extract ZIP

Hello,
I am trying to download a zip file and extract it. I have checked 1 billion times and YES the file does exist on the external server. Here is the code:
[php]

<?php set_time_limit (24 * 60 * 60); $file = fopen("http://(url taken out by me)/unzipme.zip", "r"); if (flock($file, LOCK_EX)) { $zip = new ZipArchive; $res = $zip->open('unzipme.zip'); if ($res === TRUE) { // Extracts to root dir $zip->extractTo(''); $zip->close(); // } else { // } flock($file, LOCK_UN); } else { die("Couldn't download the zip file."); } fclose($file); ?>

[/php]
It just keeps saying Couldn’t download the zip file. I have tried so many ways and none worked.

Well, the file may exist, but, are the permissions on that external server set to allow you to capture the file?
It may not allow you to do so. Can you enter the URL in a browser and download it that way?

Next, why are you locking a memory file handle? This makes no sense at all that I can think of. Let’s explain…

You have a valid file on some external site somewhere. (Note, this is not the same site as your program is on!)
It is loaded in your program into a variable which is NOT a file, but a memory handle to a variable.

If you think about this, you are giving the FILE-LOCK function no file. Therefore, it will give you a “file does not exist” ! ! !

Lastly, if you place the following two lines at the very top of your PHP code, quite often other errors details will be displayed.
I am guessing it is your attempt to lock a file that is not a file… Hope that helps!

Sponsor our Newsletter | Privacy Policy | Terms of Service