I've got a website A that holds an image, and I am now using PHP to grab that image and I want to post it via form-data media to another website. My solution now is to save the image as a file and then use CURLFile to auto-generating these form-media post fields. Is there a way that I don't need to save this image to my local file system?
What I am doing now:
$img = urlcurl::geturl($this->url); // seems to be an raw image data (png?)
$fp = fopen('./tmp/1.png','x');
fwrite($fp, $img);
$t = new CURLFile("/tmp/1.png","image/png"); // get from local file storage
$filedata = array("media" => $t);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url2);
curl_setopt($ch, CURLOPT_POSTFIELDS, $filedata);
$response = curl_exec($ch);