karelwintersky/arris.php-file-upload 问题修复 & 功能扩展

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

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

karelwintersky/arris.php-file-upload

最新稳定版本:0.2.1

Composer 安装命令:

composer require karelwintersky/arris.php-file-upload

包简介

A library to help with uploading files in PHP

README 文档

README

Uploader 🚀

Safe, simple and useful file upload class

Installing

composer require karelwintersky/arris.php-file-upload

Examples

Basic:

use Arris\Toolkit\FileUpload;

if (isset($_FILES["file"])) {
    $upload = new FileUpload($_FILES["file"]);
    $upload->setAllowedExtensions(array("png", "jpg", "jpeg", "gif"));
    $upload->setMaxSize(5); // in MB
    $upload->setPath("upload/files");
    $upload->setName("foo");
    
    if (! $upload->upload()) {
        echo "Upload error: " . $upload->getError();
    } else {
        echo "Upload successful!";
    }
}

Inline using:

use Arris\Toolkit\FileUpload;

if (isset($_FILES["file"])) {
    $upload = (new FileUpload($_FILES["file"]))->setMaxSize(20)->setPath("upload/files")->encrypt_name();
    
    if (! $upload->upload()) {
        echo "Upload error: " . $upload->getError();
    } else {
        echo "Upload successful!";
    }
}

More examples in the "examples" directory.

Methods

Name Description
setAllowedExtensions(array $extensions) Allowed file extensions (example: png, gif, jpg)
setDisallowedExtensions(array $extensions) Disallowed file extensions (example: html, php, dmg)
setAllowedTypes(array $types) Allowed mime types (example: image/png, image/jpeg)
setDisallowedTypes(array $types) Disallowed mime types
setMaxSize(int $size) Maximum file size (as MB)
setMinSize(int $size) Minimum file size (as MB)
override() Override the file with the same name
setPath(string $path) Set the path where files will be uploaded
setName(string $name) Rename the uploaded file (example: foo)
encrypt_name() Encrypt file name to hide the original name
must_be_image() Check the file is image
setMaxDimensions(int $width, int $height) Maximum image dimensions
setMinDimensions(int $width, int $height) Minimum image dimensions
setAspectRatios(array $aspect_ratios) Image aspect ratios that has to be (example: 1:1, 4:3, 16:9)
setErrorMessages(array $errors) Custom error messages
getUploadedFiles() Converts input array ($_FILES) to more usable form
Name Description Return
upload() Upload the file and return output of the check() boolean
check() Check the file can be uploaded boolean
getName() Get the uploaded file name string
getPath() Get the uploaded file name with full path string
getTempName() Get the temporary file path string
getSize() Get the uploaded file size in bytes string
getType() Get the uploaded file mime type string
getDataURL() Get the file as base64 encoded data URL string
getError() Get error message if an error occurred string

Notes

exif and fileinfo extensions must be enabled.

Based on https://github.com/iamdual/uploader

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-11