-1

I want to save an image from another server with a CRON job URL: http://servlet.dmi.dk/byvejr/servlet/byvejr_dag1?by=5466&mode=long - it is a png image I've tried with the following codes

*/5 *   *   *   *   curl http://servlet.dmi.dk/byvejr/servlet/byvejr_dag1?by=5466&mode=long > /home/klintweb/public_html/gal.klintmx.dk/images/vejr.png

The image is saved in the folder, but it can't be published because of an error - the file-size is 0 byte Is there a way to do this

KlintWeb
  • 31
  • 1
  • 10

1 Answers1

0

The job is done with a php script

$profile_Image = 'http://servlet.dmi.dk/byvejr/servlet/byvejr_dag1?by=5466&mode=long'; //image url
$userImage = 'byvejr_dag1_5466.png'; // renaming image
$path = '/home/klintweb/public_html/gal.klintmx.dk/images/vejr';  // your saving path
$ch = curl_init($profile_Image);
$fp = fopen($path . $userImage, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec($ch);
curl_close($ch);
fclose($fp);

and this CRON job

0,30    *   *   *   *   /usr/bin/php /home/klintweb/public_html/gal.klintmx.dk/byvejr.php

and this .htaccess in the folder images/vejr to make sure it's not cached

<IfModule mod_expires.c>
# disable caching forthis directory mod_expires for this directory
ExpiresActive off
</IfModule>
KlintWeb
  • 31
  • 1
  • 10
  • @fedorqui might have a point, but partly the answer is written after my own answer to the question, and secondly, fedorqui writes nothing about how to escape the & My answer is a complete answer to the question - and it works perfect, even there could be others – KlintWeb Jun 15 '16 at 23:05