Download a zip file from web and enumerate through contents to save

Posted on 2011-02-20
Last Modified: 2012-06-21
I have a web url which if accessed will download the file.  There are no security issues or any passwords.  I would like to grab the file using PHP and enumerate through the contents to rename and save individually.
Question by:Dean_Kletter
  • 4
  • 4
LVL 11

Expert Comment

ID: 34940415
All that you need is in this tutorial:

just start reading from step number 5.

For getting the .zip file from the website you can use the file_get_contents() funtion:

For save it in your own server use file_put_contents.

After this point you can use the code in the tutorial (from step 5), and just add the renaming routine.

Hope this helps!.


Author Comment

ID: 34940498
Ok, when I save it on my own server
Private function download_pics ($dl_link){
	$zip = new ZipArchive;
	$getFile = file_get_contents($dl_link);
	$tempFile = file_put_contents($getfile);
	$x = $zip->open($tempFile);
	if  ($x === true){
	  } ELSE {
  	  die("<br/>There was a problem unpacking the .ZIP archive.");

Open in new window


Author Comment

ID: 34940502
It fails with the error, wondering if I need to save the files physically on my server before I can work with it?
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

LVL 11

Expert Comment

ID: 34940530
wondering if I need to save the files physically on my server before I can work with it?

Yes, that's why I suggest you to use a combination of file_get_contents() and file_put_contents().

With the firstone you read the file remotely, with the second one you save it in your server before start working over it.

Other way it will not work.


Author Comment

ID: 34940541
Well, I did use those two commands you suggested, although I obviously did something incorrectly.  The code I pasted above is the combination of your two suggestions.  You see anything in there I'm missing.
LVL 11

Accepted Solution

VanHackman earned 500 total points
ID: 34940569

>> You see anything in there I'm missing?

Yes, at line 4:

$tempFile = file_put_contents($getfile);

The file_put_contents function takes 2 arguments, the path to where you will save the file, and the data for the file itself:

so it should be something like:

$tempFile = file_put_contents("", $getfile);

So, read carefully the tutorial and the Php manual pages for the functions...:


Author Closing Comment

ID: 34940647
pft.. Details, how much could they matter to syntax!

Thanks for your help.
LVL 11

Expert Comment

ID: 34945581
You are welcome.

Also, thank you for the points, glad to heard it works.

Best regards,
Oxygen+ Team

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question