I want to download images from my server without clicking anything - when my php file executes it will download automatically, but the problem is the file is corrupt. However, when I paste the url directly in the browser and download, it works perfectly. So why does my implementation below not work? Any ideas about this?
Here's my code:
$url_to_image = 'https://hideserver.com/axul-display/assets/ads/';
$ch = curl_init($url_to_image);
$my_save_dir = 'assets/ads/';
$filename = basename($url_to_image.'ads-id-4.gif');
$complete_save_loc = $my_save_dir . $filename;
$fp = fopen($complete_save_loc, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
curl_exec($ch);
curl_close($ch);
fclose($fp);