Giter Site home page Giter Site logo

think-upload's Introduction

Thinkphp5 FileUplaod Library.

Thinkphp5 has only local file upload feature,But many projects require use Qiniu or Aliyun cloud storage.So i wrote a library.

First

Create upload.php file on the application/extra directory.And copy the following code:

return [
    'driver' => 'aliyun',
    /** limit file size,unit:byte,if the value equal 0 the file size will not restricted.  */
    'size' => 1024 * 1024,
    /** allow file extension.if is empty the file extension has no limit. */
    'ext'  => [],
    /** allow file type by file mime.if is empty the file type has no limit. */
    'type' => [],
    'path' => './images/',
    'default' => [
        /** access url */
        'remote_url' => 'http://xx.com/public/',
    ],
    'qiniu' => [
        'access_key' => '',
        'secret_key' => '',
        'bucket' => '',
        /** access url */
        'remote_url' => '',
    ],
    'upyun' => [
        'username' => '',
        'password' => '',
        'bucket' => '',
        /** access url */
        'remote_url' => '',
    ],
    'aliyun' => [
        /** Internal net url or External net url */
        'oss_server' => '',
        'access_key_id' => '',
        'access_key_secret' => '',
        'bucket' => '',
        /** access url */
        'remote_url' => '',
    ],
];

Please open bucket read authority if you use aliyun driver.because bucket read authority was closed,the server will return AccessDeined.

Usage

<?php
use Qsnh\think\Upload\Upload;

$upload = new Upload(config('upload'));

// $result = $upload->upload('avatar', '123.jpg');
$result = $upload->upload('avatar'); // first parameter is folder path; second parameter is custom filename(default: null) 

if (!$result) {
    $this->error($upload->getError());
}

halt($result);

The upload() method has an optional parammeters.It default value is file.And it equal the name of file component.

think-upload's People

Contributors

qsnh avatar terranc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.