定制 mohamed-amine/file-uploader 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

mohamed-amine/file-uploader

Composer 安装命令:

composer require mohamed-amine/file-uploader

包简介

a light PHP script that upload your files/images with easy steps & some cool features like compression & resizing

README 文档

README

Simple Easy To use PHP File Uploader

install Via composer :

composer require mohamed-amine/file-uploader

How To Use :

Html :

Single file upload :
<form method="POST" enctype="multipart/form-data">
    <input type="file" name="myfile" /><br>
    <input type="submit" value="Upload File"/>
</form>
Multi files upload :
<form method="POST" enctype="multipart/form-data">
    <input type="file" name="myfile[]" /><br>
    <input type="file" name="myfile[]" /><br>
    <input type="file" name="myfile[]" /><br>
    <input type="submit" value="Upload File"/>
</form>

Simple File upload:

NOTE: every validation or other process should be done before uploading (calling save() method).

<?php
// create uploader instance
$file = Upload\Upload('myfile');

// upload files to defined directory
$data = $file->save('myDirectory');

var_dump($data);

// this will output an array which contains uploaded files data
// [
//      'id' => 'sf23s6sdf23s',
//      'name' => 'myFileName',
//      'path' => 'document/images/photo.jpg'
// ]
// 
// Or in case of multi file upload
//
// [
//      [
//          'id' => 'er23sfd3p4uo ',
//          'name' => 'photo1',
//          'path' => 'document/images/photo1.jpg'
//      ],
//      [
//          'id' => 'sf23s6sdf23s',
//          'name' => 'photo2',d
//          'path' => 'document/images/photo2.jpg'
//      ]
// ]
//

Validation:

Available validation methods are:

  • size(float $min, float $max) min & max are in MB
  • extension(array $allowed)
  • number(int $min, int $max = null)
$file = Upload\Upload('myfile');

// validate
$file->validate()->extension(['jpg', 'gif'])->size(0.5, 10)->number(2);

// check for validation errors
if ($file->isValide()) {
    var_dump($file->getErrors();
}

// upload files
$file->save('myDirectory');

Processing uploaded files:

Note: this function require php-gd to be installed on the server. currently only images can be processed, available methods are:

  • compress(int $quality) NOTE : compresssion level 0 to 100 lower is the most compressed and lowest quality
  • resize(int $width, int $height)
  • setName(array $names)
$file->process()->compress(75)->resize(500, 800)->setName(['firstname', 'secondname']);

// or

$file->process()->compress(75);
$file->process()->resize(500, 800);
$file->process()->setName(['firstname', 'secondname']);

$file->save('myDirectory');

contribution

any contribution will be welcomed.

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-09-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固