You need to implement loading by URL (not local file) using cURL.


curl_setopt($ch, CURLOPT_POSTFIELDS, array('file'=>"http://site.ru/image.jpg")); 

But this code does not work.

  • Do you need to download a remote file to your computer or vice versa? - KryDos
  • On the contrary - upload to another server. Those. there is site site.ru, in which the picture, there is site skript.ru, in which the script and there is site site.ru, on which you need to download. - nick777
  • As I recall, you need to specify the full path to the file, not the url. Those. something like `curl_setopt ($ ch, CURLOPT_POSTFIELDS, array ('file' => '@'. dirname ( FILE ). '/ image.jpg'));` - Indifferent

1 answer 1

In your case, you must first upload a picture to the site skript.ru for example:

 $ch = curl_init(); $file = fopen('image.jpg', 'w'); curl_setopt($ch, CURLOPT_FILE, $file); curl_setopt($ch, CURLOPT_URL, 'http://site.ru/image.jpg'); curl_exec($ch); 

And then upload to site1.ru.

Or you can do this:

create a script on site site1.ru that will wait for some post parameters (for example, 'file' => 'image address') and after receiving the image address, it will download it with the above-described piece of code.


 curl_setopt($ch, CURLOPT_POSTFIELDS, array('file'=>"http://site.ru/image.jpg")); 

You here transmit the address of the picture and not the picture itself.

  • The essence of this question was that I wanted to get around these 2 ways, but thanks anyway) - nick777