承接 lodev09/php-upload 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

lodev09/php-upload

最新稳定版本:2.0.2

Composer 安装命令:

composer require lodev09/php-upload

包简介

A very simple yet useful helper class to handle PHP file uploads.

README 文档

README

A very simple yet useful helper class to handle PHP file uploads.

Features

  • Supports Multiple file uploads
  • Supports Exif for images
  • Built-in and Custom validations
  • Simple implementation
  • or you can ask for more ...

Installation

$ composer require lodev09/php-upload

Usage

HTML

<form action="index.php" method="post" enctype="multipart/form-data">
    <input type="file" name="files[]" multiple /><br>
    <input type="submit" name="submit" value="Submit" />
</form>

PHP (server side)

use \Upload\Upload;

if (isset($_FILES['files'])) {
    $validations = array(
        'category' => array('document', 'image', 'video'), // validate only those files within this list
        'size' => 20 // maximum of 20mb
    );

    // create new instance
    $upload = new Upload($_FILES['files'], $validations);

    // for each file
    foreach ($upload->files as $file) {
        if ($file->validate()) {
            // do your thing on this file ...
            // ...
            // say we don't allow audio files
            if ($file->is('audio')) $error = 'Audio not allowed';
            else {
                // then get base64 encoded string to do something else ...
                $filedata = $file->get_base64();

                // or get the GPS info ...
                $gps = $file->get_exif_gps();

                // then we move it to 'path/to/my/uploads'
                $result = $file->put('path/to/my/uploads');
                $error = $result ? '' : 'Error moving file';
            }

        } else {
            // oopps!
            $error = $file->get_error();
        }

        echo $file->name.' - '.($error ? ' [FAILED] '.$error : ' Succeeded!');
        echo '<br />';
    }
}

?>

Feedback

All bugs, feature requests, pull requests, feedback, etc., are welcome. Visit my site at www.lodev09.com or email me at lodev09@gmail.com

Credits

© 2018 - Coded by Jovanni Lo / @lodev09

License

Released under the MIT License. See LICENSE file.

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-02-03