试图用PHP下载远程图像

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/

I guess it's pretty obvious, but did you try to open the URL in your browser? Can you see the image?

If the answer to the above is YES (most likely), most likely the remote party is blocking scripts from fetching the resource. The solution is to use cURL emulating as best as possible the behaviour of a regular browser, in terms of HTTP headers.

I would start from the most obvious ones which are CURLOPT_USERAGENT and CURLOPT_USERAGENT, set them at the values they expect and you should be fine. More complex access controls involve cookies and sessions, which is more complicated because you would have to fetch the referring page, store the cookie, and send it while fetching the resource.

UPDATE:

While the above is true, it was not the problem the asker had, this simple script should work as-is:

$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)');
$data = curl_exec($ch);
file_put_contents("local_file.jpg", $data);