D
D
dkrylov2018-04-27 12:36:39
PHP
dkrylov, 2018-04-27 12:36:39

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']);

But how can I accept this whole thing on the second server?)
...mb something like that? But not so much)
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);
    }

The question is supplemented with one important detail.
"Upload-file-within-rest-json-concept"

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dkrylov, 2018-04-27
@dkrylov

Answer found!
https://ru.stackoverflow.com/questions/428753

A
Artem, 2018-04-27
@proudmore

https://stackoverflow.com/questions/2578128/http-t...

A
Alexander Lykasov, 2018-04-27
@lykasov-aleksandr

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 question

Ask a Question

731 491 924 answers to any question