PHP code example of igogo5yo / yii2-upload-from-url
1. Go to this page and download the library: Download igogo5yo/yii2-upload-from-url library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
igogo5yo / yii2-upload-from-url example snippets
$model = new Post();
$model->load(Yii::$app->request->post());
$file = UploadFromUrl::getInstance($model, 'image');
//if second parameter is TRUE it writes uploaded file path to this model property
$file->saveAs('uploads/yii.png', true);
echo $model->image; // uploads/yii.png
$model = new Post();
$model->image = 'http://static.yiiframework.com/files/logo/yii.png';
$file = UploadFromUrl::initWithModel($model, 'image');
//if second parameter is TRUE it writes uploaded file path to this model property
$file->saveAs('uploads/yii.png', true);
echo $model->image; // uploads/yii.png
$url = 'http://static.yiiframework.com/files/logo/yii.png' ;
$path = 'uploads/yii.png';
$file = UploadFromUrl::initWithUrl($url);
$file->saveAs($path);
//Set to model
$model = new Post();
$model->image = $path;