You need to send a file (image) to this site. They have an API . I try to send from a local site (on OpenServer'e), if I substitute the address of a picture on the Internet, then all the rules, and if I specify in the same way (full URL) on my local "site", I get an error 403 (error on the resource).

$img_name_loc = '33.jpg'; 

// $ ch = curl_init (' http://uploads.ru/api?upload=http://www.bugaga.ru/uploads/posts/2017-03/1488368729_v-parke-yellouston-11.jpg&thumb_width=800&format= json '); // <- this is how it works

 $ch = curl_init('http://uploads.ru/api?upload=http://site.loc/uploads/'.$img_name_loc.'&thumb_width=800&format=json'); // <- **так НЕ работает** curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $html = curl_exec($ch); curl_close($ch); 

ideally, it would generally send directly from <input id="uplimg" type="file" accept="image/*"> suspect that one of the problems is that it is a localhost.

  • Something is not clear - twice the "local site" was written in the question. - Alexey Shatrov
  • what is not clear and where two times? from lokalki trying to send to http://uploads.ru/ in the question is listed as " this site" - medvedev
  • 403 curl issues or API? And the local site on which domain is deployed? - Alexey Shatrov
  • API in the answer gives. When the image is from the Internet, then the normal answer is 200 and the parameters I need, when from a LAN, then 403 and the error text. Lokalka site.loc, in the code line $ch = curl_init('http://uploads.ru/api?upload=http://site.loc/uploads/'.$img_name_loc.'&thumb_width=800&format=json'); - medvedev
  • Your site.loc is visible only to you and only on your local network, uploads.ru is a site on the Internet, and does not know about it because domain name, again, is known only in YOUR local network. Use POST to transfer the image (although it is not clear how, and there are no examples), try stackoverflow.com/questions/3433542/curl-php-send-image - Daniel Protopopov

1 answer 1

Really the problem is that it is a local computer.

The site http://uploads.ru tries to upload an image to the address you conveyed conditionally via file_get_contents , and if http://test1.ru/33.jpg opens for you, then for uploads.ru it will be a completely different resource, which gives he is 403.

The API says that

  • Download files from a computer or the Internet
  • Works with POST and GET

But, there are no examples of local loading, it is POSSIBLE that you simply pass a local path, for example, as you say, “33 .jpg” at the beginning, the API will determine that there is no protocol indication and this is a local path.

  • I decided to check my suspicion and your statement about lokalki. Indeed, the problem is this. Simply passing the local path does not work, but I’ll try to play $_FILES['image']['tmp_name']; with $_FILES['image']['tmp_name']; , can get all the same with input'a directly throw, I pass my server - medvedev