codad5/file-helper
Composer 安装命令:
composer require codad5/file-helper
包简介
FIle Uploader is a php package to aid fast , easy and safe file upload
README 文档
README
FIle Uploader is a php package to aid fast , easy and safe file upload
installation
composer require codad5/file-helper
Features
- Fast and easy to use with method chaining
- Good error management
- Safety management
- works for both multiple file upload and single file upload
Usage
index.php
<form action="./upload.php" method='post' enctype="multipart/form-data"> <input type="file" name="test[]" multiple> <input value="submit" type="submit"> </form>
upload.php
<?php include(__DIR__ . '/../vendor/autoload.php'); $file_upload_controller = new Codad5\FileHelper\FileUploader('test', "uploads/");
test - the name given to the $_FILES array by default - for refrence $_FILES['test]`
uploads/ - Upload path relative to upload.php
To add allowed extension
#any other extension aid the given will give error or ignored depending on your error settings $file_upload_controller->add_ext('svg', 'png');
To set File Prefix
# for unique id can be replaced with uniqid('', true) $file_upload_controller->set_prefix('my prefix');
To set max and min size
$file_upload_controller->set_sizes(10000, 20);
10000 - This is the maximum file size allowed, to ignore for your .ini config set it to null
20 - This is the minimum file size allowed default equals 0
Turing on/Off Error reporting
/** * This is use to turn on and off reporting of the upload process * @param bool $file_error - to report error imbound in file from request if `true` else ignore * @param bool $size_error - TO report size related error if `true` else ignore * @param bool $type_error - To report error related to file type if `true` else ignore */ $file_upload_controller->set_reporting(true, false, true);
- The first param
$file_erroris to report error imbounded in file from request as found in$_SERVER['test'] - The second param
$size_erroris to report size related error depending on your settings - The Third param
$type_erroris to report error if a file is not part of the allowed file
NOTE: If any is
falseand error is found it will ignore the file and continue upload with out the file
Moving the file
$file_upload_controller->move_files();
Get Uploaded file path
$upload_path = $file_upload_controller->get_uploads(); foreach ($upload_path as $key => $value) { # code... echo "This file has been uploaded to ".$value['uploaded_path']."<br/>; }
- This returns a multi-dimensional array of each array with the following key
uploaded_path- The final uploaded file with path relative to the script tagupload.phpname- The name of the filesize- The size of the filetype- The file Typeext- The file extension
Method Chaining
$file_upload_controller = new \Codad5\FileHelper\FileUploader('tes', "uploads/"); $uploaded_file_array = $file_upload_controller ->set_reporting(false, false, false) ->add_ext('png', 'pdf') ->set_prefix('cool Stuff') ->move_files() ->get_uploads(); foreach ($uploaded_file_array as $key => $value) { # code... echo "This file has been uploaded to ".$value['uploaded_path']."<br/>"; }
This documentaion will be updated in time as the project grows for enquire and more information contact me here
Built with 💗 by Chibueze Michael A.
codad5/file-helper 适用场景与选型建议
codad5/file-helper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 60 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 08 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 codad5/file-helper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 codad5/file-helper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 60
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-07