I've trying to download remote images(from more than one site) but any of these codes worked
allow_url_fopen is on but these code will return 0 bytes
$url = 'http://example.com/image.php';
$img = 'teste.jpg';
file_put_contents($img, file_get_contents($url));
or
copy('http://example.com/image.php', 'teste.jpg');
When I use curl(that is enabled on host) this error appears:
Error: The requested resource could not be loaded. libcurl returned the error: Empty reply from server
curl code :
$ch = curl_init('http://example.com/image.php');
$fp = fopen('teste,jpg, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
Edit: Tried following curl opt too:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)');
curl_setopt($ch, CURLOPT_FILE, $lfile);
site is hosted by 000webhost, and after trying my whole day with differents codes I had to use a proxy to access my site because it was blocking me
Edit 2:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"h.mhcdn.net/store/manga/10738/thumb_cover.jpg?v=1476422230");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)');
//die("here1");
$data = curl_exec($ch);
die("here2");
file_put_contents("test.jpg", $data);
die("here3");
//curl_setopt($ch, CURLOPT_FILE, "test.jpg");
Tried code above but it wont reach "die("here2");"(page wont load) only the die("here1");
Edit 3:
$url = "http://h.mhcdn.net/store/manga/10738/thumb_cover.jpg?v=1476422230";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)');
//die("here1");
$data = curl_exec($ch);
file_put_contents("local_file.jpg", $data);
die("here2");
Can't reach here2, only here1
Edit 4: here's the problem: port 80 has been blocked for outgoing connections at 000web : https://www.habschned.com/000webhost-com-blocking-port-80-for-outbound-traffic-no-more-curl/