0

I want to download content of a URL and then post it via cURL. I can know I can do something like this

$urlToDownload = "http://www.example.com/image.png";
copy($urlToDownload, $tmp);

$data = array(
    'file' => '@' . $tmp . ';filename=' . $name
);

...
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

Is there anyway that I can directly post data of URL without create temporary file?

invisal
  • 11,075
  • 4
  • 33
  • 54
  • [file_get_contents](http://php.net/manual/en/function.file-get-contents.php) – adeneo Jun 07 '15 at 13:20
  • Posting data is an HTTP request, so you do have to build this request. Thus I don't see how it could be possible not having to dwonload the data before sending it. – Ivan Gabriele Jun 07 '15 at 13:23
  • @adeneo I recommend rereading the question again. – Blue Jun 07 '15 at 13:23
  • @FrankerZ - maybe I misunderstood, but copy writes a file, wasn't the question how to get the image without creating a temporary file ? – adeneo Jun 07 '15 at 13:35
  • @adeneo No, it was how to post an image without having to create a temporary file for upload. – Blue Jun 07 '15 at 13:36
  • @FrankerZ - Huh? Now the OP is getting an image from an URL by writing an image file to disk. Then he uploads that image somewhere else using cURL. Wasn't the point to get the image from that URL and post it with cURL *without* first writing it to a file ? – adeneo Jun 07 '15 at 13:40
  • @adeneo, I know I can get content by using file_get_contents, but after I get content, how to post file content without creating temporary file? – invisal Jun 07 '15 at 13:42
  • I'm not sure you can, cURL seems to only accept an url, but you can use `stream_context_create` and `file_get_contents` to do the same thing, here's something to get started -> http://stackoverflow.com/questions/2445276/how-to-post-data-in-php-using-file-get-contents – adeneo Jun 07 '15 at 13:48

0 Answers0