I am trying to transfer the image from the remote server to the controller for further processing.
$url_image = 'http://vpoltave.info/uploads/ab/e977e56d31c874a1780528411755e2-bigimg.png'; $image = file_get_contents($url_image); $mime_type = getimagesize($url_image)['mime']; $file_name = basename($url_image); $boundary = '--------------------------' . md5(microtime(true)); $eol = '\r\n'; $url = SITE_URL . '/upload/post-photo'; $file_content = '--' . $boundary . $eol . 'Content-Disposition: form-data; name="file"; filename="' . $file_name . '"' . $eol . 'Content-Type: ' . $mime_type . $eol . $eol . //'Content-Transfer-Encoding: binary' . $eol . $eol . $image . $eol; $file_content .= '--' . $boundary . '--' . $eol; $response = file_get_contents($url, false, stream_context_create([ 'http' => [ 'method' => 'POST', 'header' => 'Content-Type: multipart/form-data; boundary=' . $boundary, 'content' => $file_content ] ])); var_dump($response); exit;
At this point in the controller stub:
var_dump($_FILES); exit;
Request Headers:
{ "Content-Type":"multipart/form-data; boundary=--------------------------50fdc74116a157d67cdcd07aaf7dbf29", "User-Agent":"PHP (mysite.com), hosted by www.ukraine.com.ua", "Content-Length":"471222", "Connection":"close", "Geoip-Country-Code":"UA", "X-Real-Ip":"xx.xxx.xxx.xx", "Host":"mysite.com" }
But in $ response, an empty array is always returned. Tell me what is missing ... Why is the $ _FILES array empty?