Answer the question
In order to leave comments, you need to log in
How to upload a photo to the server via a direct link?
At the moment, you have to upload a photo to your directory and then send it through new CURLFile(/my_direcroty), this function works with files that are on the server, it does not work with direct links(new CURLFile(www.site.ru/*.jpg )). Does anyone know how to download from a URL?
I tried to do it through file_get_contents, but nothing comes out:
define('MULTIPART_BOUNDARY', '--------------------------'.microtime(true));
$header = 'Content-Type: multipart/form-data; boundary='.MULTIPART_BOUNDARY;
define('FORM_FIELD', 'uploaded_file');
$filename = "https://thefancy-media-ec2.thefancy.com/original/20120819/167936702336205476_aa4d348f12c5.jpg";
$file_contents = file_get_contents($filename);
$content = "--".MULTIPART_BOUNDARY."\r\n".
"Content-Disposition: form-data; name=\"".FORM_FIELD."\"; filename=\"".basename($filename)."\"\r\n".
"Content-Type: image/jpeg\r\n\r\n".
$file_contents."\r\n";
$content .= "--".MULTIPART_BOUNDARY."\r\n".
"Content-Disposition: form-data; name=\"foo\"\r\n\r\n".
"bar\r\n";
$content .= "--".MULTIPART_BOUNDARY."--\r\n";
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => $header,
'content' => $content,
)
));
$response = file_get_contents($uploadUrl, false, $context);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question