1

I have a WordPress site where we are facing some issues using images.

The images exist on the server, when we access the images via URL, it works and the image shows.

But when we use curl, file_get_contents, fopen, copy etc command to get or access the file, we get the 404 error status code.

Can anyone can help me, I don't know if it's a server issue or WordPress issue.

Below is my sample of code:

$url = "http://blogbucket.in/wp-content/uploads/files/0B6IGyYw9A5RYS0tNelJrdmFsMTQ/airbitz-co1.png";
$ch = @curl_init($url);
@curl_setopt($ch, CURLOPT_HEADER, true);
@curl_setopt($ch, CURLOPT_NOBODY, true);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
@curl_setopt($ch, CURLOPT_FAILONERROR, true);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
@curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');

@curl_exec($ch);
$header = curl_getinfo($ch);
curl_close($ch);
echo "<pre>";
print_r($header);
echo "<pre>";

Below are the links I've looked at so far.

You can try it here.

Community
  • 1
  • 1
Vaibhav Singhal
  • 511
  • 1
  • 4
  • 25

1 Answers1

2

The images exist on the server, when we access the images via URL, it works and the image shows.

But when we use curl, file_get_contents, fopen, copy etc command to get or access the file, we get the 404 error status code.

This url returns 404 response with image payload. So you can disregard the response code and use the image data from the response body.

Community
  • 1
  • 1
weirdan
  • 2,499
  • 23
  • 27