Skip to content

femike/yii2-upload-from-url

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UploadFromUrl extension for Yii 2

Latest Stable Version Total Downloads Latest Unstable Version License Dependency Status This is the upload file from url address extension for Yii 2. It have class UploadFromUrl for upload files from URL and it have FileFromUlrValidator for validate model attribute with file from url.

Please submit issue reports and pull requests to the main repository. For license information check the LICENSE-file.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist igogo5yo/yii2-upload-from-url

or add

"igogo5yo/yii2-upload-from-url": ">=1.0"

to your composer.json file

Usage

Example 1

$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

Example 2

$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;

Example 3

$url = 'http://static.yiiframework.com/files/logo/yii.png' ;
$path = 'uploads/yii.png';
$model = new Post();

$file = UploadFromUrl::initWithUrlAndModel($url, $model, 'image');
$file->saveAs( $path, true );   

echo $model->image; // uploads/yii.png

Validation Example

[
...
     [['image'], 'igogo5yo\uploadfromurl\FileFromUrlValidator', 'extensions' => 'csv', 'mimeTypes' => 'text/plain'],
...
]

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%