Solved

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

Posted on 2011-02-20
8
855 Views
Last Modified: 2012-06-21
I have a web url http://www.mycompany.com/archive/myarchive.zip 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.
0
Comment
Question by:Dean_Kletter
  • 4
  • 4
8 Comments
 
LVL 11

Expert Comment

by:VanHackman
Comment Utility
All that you need is in this tutorial:

http://net.tutsplus.com/articles/news/how-to-open-zip-files-with-php/

just start reading from step number 5.


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

http://php.net/manual/en/function.file-get-contents.php

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!.
VanHackman

0
 

Author Comment

by:Dean_Kletter
Comment Utility
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){
	  $zip->extractTo('IMG/');
	  $zip->close();
	  unlink($tempFile);
	  } ELSE {
  	  die("<br/>There was a problem unpacking the .ZIP archive.");
	  }
  }

Open in new window

0
 

Author Comment

by:Dean_Kletter
Comment Utility
It fails with the error, wondering if I need to save the files physically on my server before I can work with it?
0
 
LVL 11

Expert Comment

by:VanHackman
Comment Utility
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.


0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:Dean_Kletter
Comment Utility
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.
0
 
LVL 11

Accepted Solution

by:
VanHackman earned 500 total points
Comment Utility

>> 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:

http://php.net/manual/en/function.file-put-contents.php

so it should be something like:

$tempFile = file_put_contents("MyTempFile.zip", $getfile);

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

http://php.net/manual/en/function.file-put-contents.php
http://php.net/manual/en/function.file-get-contents.php

Cheers!
0
 

Author Closing Comment

by:Dean_Kletter
Comment Utility
pft.. Details, how much could they matter to syntax!

Thanks for your help.
0
 
LVL 11

Expert Comment

by:VanHackman
Comment Utility
You are welcome.

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

Best regards,
Oxygen+ Team
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
PHP Startup Error 12 27
how to resize preview image 4 28
comparing strings that contain line breaks 18 34
Wordpress Body Class 5 8
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now