Answer the question
In order to leave comments, you need to log in
How to transfer a file between two sites in yii2 (rest+json)?
Hello, dear programmers)
There is a task - it is necessary to transfer a file from one project to yii2 to another project also to yii2. The trick is that the file CANNOT be transferred to the open (i.e. give a link to the file, and on the second project curl or download something else).
I seem to have come up with this method:
Yii::$app->response->sendFile($path, $model->file, ['mimeType'=>'application/zip']);
private function download($url, $file)
{
$myFile = @fopen($file, "w");
$resource = curl_init();
curl_setopt($resource, CURLOPT_URL, $url);
curl_setopt($resource, CURLOPT_FILE, $myFile);
curl_setopt($resource, CURLOPT_HEADER, 0);
curl_exec($resource);
curl_close($resource);
fclose($myFile);
}
Answer the question
In order to leave comments, you need to log in
If you don’t use anything else, but use only Yii, then you make a special controller with an action on the receiving site, which will receive a file from the source site via POST.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question