Simple download script request for cron

Hi all,

If anybody could please help me!

I’ve a problem, probably not so difficult most of you…
There is https://fakesite.com/example where is xml file. When I give this URL explorer asks, what I would like do this file, where I want save etc.

I need a small php script to my server, which is enable to download this xml file and save into my predefined server folder. If the file (filename) already exist in my root folder, overwrite them. The file name not important, could be original or anything with extension xml. This php script should have run, when cron calls.

Any help would be appreciated….

Thanks in adcance

Example modified from this tutorial:

[php]$curl = curl_init(‘http://some-url.com/some-file.xml’);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$contents = curl_exec($curl);

file_put_contents(’/your/server/path/file.xml’, $contents);

curl_close($curl);[/php]

We create the curl object with curl_init, set an option with curl_setopt, save the downloaded file into your path with file_put_contents then close the curl connection (curl_close).

Hi jSherz,

Thanks for your prompt answer. The sripts is working fine manually; i mean if I write the url of the php, the script run and save the xml. the defined folder.

Cool, thank you ever so much (definitely I have to learn the php 8))

The problem is if I set http://www.mysite.com/downoader.php in cron, the script not runs automatically…

Can you post the full cron command?

I see a lot of people use something similar to:

php -q /path/to/file.php > /dev/null

Meanwhile the problem have been solved. I’ve conversation with my host, and they set the pnp.ini…

Thanks again jSherz
If I can, help you back with graphic design or 3D

By the way, thanks for Youtube tutorial GREAT, I will watch each one. :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service