Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Thomas van der Zel
Thomas van der Zel
16,796 Points

Downloading with PHP

Hi,

I've been struggling with this issue for hours now and I'm hoping anyone out here knows the solution.

I wrote a php-script extracting a zip file and doing stuff with it's content. This script works fine. The problem is this:

The script uses file.zip, which is located on my server. However the file changes daily and is supplied by a 3rd party through a url (say 'http://www.example.com/zip'). In this url is no filename or extension, but when I open it in a browser it downloads file.zip.

I'm hoping to find a way to automate the download so that I don't have to go in my browser to download the file and then upload it to my server every single day.

I hope you can help me out!

3 Answers

It sounds like you have the script and just need to run it every day at a set time. Looking for the answer, I came across this:

http://stackoverflow.com/questions/120228/php-running-scheduled-jobs-cron-jobs

What you need to do is set a chronjob on your server. Reading that triggered my memory that I did that on some web site before I knew what I was doing. Depending on your ISP, you can do it from the cPanel. Other solutions are touched on in the link above.

Steven Walters
Steven Walters
10,573 Points

You should be able to pull the file down with cURL. Once you get the curl working you could add it to your script.

http://php.net/manual/en/curl.examples-basic.php

http://stackoverflow.com/questions/22155882/php-curl-download-file

I misunderstood your initial post. I think the answer is a combination of my first post and Steven Walters post. His post addresses the script, mine the scheduling.