igogo5yo/yii2-upload-from-url
Composer 安装命令:
composer require igogo5yo/yii2-upload-from-url
包简介
UploadFromUrl extension for Yii Framework 2
README 文档
README
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->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
Example 2
$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 3
$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 4
$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'],
...
]
Run Tests
phpunit --bootstrap tests/bootstrap.php tests
统计信息
- 总下载量: 78.35k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-05-29