macroscope29/yii2-file-upload 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

macroscope29/yii2-file-upload

Composer 安装命令:

composer require macroscope29/yii2-file-upload

包简介

Yii2 FileUpload – PHP library for uploading files to local server or Amazon S3

README 文档

README

Stable Version License

Yii2 FileUpload – PHP library for uploading files to your server or Amazon S3. It makes easy for developers to handle with yii2 UploadedFile instances. It's also possible to upload files via URLs from external sources.

Getting Started

Installation

The preferred way to install this extension is through composer.

Note: Check the composer.json for this extension's requirements and dependencies. Read this web tip /wiki on setting the minimum-stability settings for your application's composer.json.

Either run

$ php composer.phar require vlaim/yii2-file-upload "dev-master"

or add

"vlaim/yii2-file-upload": "dev-master"

to the require section of your composer.json file.

Do not forget include Composer autoloader and define namespace for library

<?php
require '/path/to/vendor/autoload.php'; 
use vlaim\fileupload\FileUpload;

Quick Examples

Upload a file to your local server

$photo = UploadedFile::getInstance($model, 'photo'); 
$uploader = new FileUpload(FileUpload::S_LOCAL);

Upload a file to Amazon S3

This code uploads a file to Amazon S3. You must provide an associative array as second argument in FileUpload constructor in following way:

$photo = UploadedFile::getInstance($model, 'photo'); 
$uploader = new FileUpload(FileUpload::S_S3, [
    'version' => 'latest',
    'region' => '<regiongoeshere>',
    'credentials' => [
        'key' => '<keygoeshere>',
        'secret' => '<secretgoeshere>'
    ],
    'bucket' => '<bucketgoeshere>'
]);

Methods

setUploadFolder(string $folder)

Sets folder name in which files will be uploaded to.

Default to 'uploads'

$uploader->setUploadFolder('photos');

setFsPath(string $fsPath)

(Only for Local mode)

Sets path in which files will be uploaded to. You can provide absolute or relative path

Default to /

$uploader->setFsPath('/var/www/path/to/your/app/');

setFsUrl(string $url)

(Only for Local mode)

Sets url. For example, if you set path to 'http://static.example.com' file after uploading will have URL http://static.example.com/path/to/your/file

Default to /

$uploader->setFsPath('http://pathtoyoursite.com');

hashFilename(boolean $hash)

Defines if upload filename needs to be hashed using md5 algorythm in following way:

md5($fileName . time() . mt_rand(0, 30) // file.png upload filename will be 2122c3a6ad9997af28cab44b7fe7ab90.jpg

Default to true

$uploader->hashFilename(false);

setACL(string $acl)

Sets Access Control List.

Read more at http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html

$uploader->setACL('public-read');

Catching and handling exceptions

To catch exceptions use FileUploadException class

<?php
use vlaim\fileupload\FileUploadException;

try{
	//your code goes here
}
catch(FileUploadException $e){
	echo $e->getMessage();
}

Tests

Will be added soon :)

Issues

Bug reports and feature requests can be submitted on the Github Issue Tracker.

License

yii2-file-upload is released under the MIT License. See the bundled LICENSE.md for details.

统计信息

  • 总下载量: 159
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固