vista-php/upload
最新稳定版本:1.0.3
Composer 安装命令:
composer require vista-php/upload
包简介
Upload files library
README 文档
README
Introduction
Vista PHP Upload module is a part of Vista PHP Framework, but can also be used as a stand alone file manipulation package for PHP. It is designed to simplify file uploads and file manipulation in PHP.
Getting Started
Installation
composer require vista-php/upload
Usage
All you need to do is instantiate the Vista\Upload\FileUploader class and call the upload method.
Constructor of the FileUploader class takes one parameter:
string $name- The name of the file input field in the form.
Example:
use Vista\Upload\FileUploader; $uploader = new FileUploader('file'); $uploader->upload();
Configuration
You can configure the allowed mime types, maximum file size, upload directory, allow overwrite, file name, file nameprefix, file name suffix, allowed file types and perform manual validation based on the configured criteria.
Example:
use Vista\Upload\FileUploader; $uploader = new FileUploader('file'); $uploader->setAllowedMimeTypes(['image/jpeg', 'image/png', 'image/gif']) ->setMaxFileSize(1024 * 1024); // 1MB ->setUploadDirectory(__DIR__ . '/uploads') // It should be a writable directory ->setAllowOverwrite(true) // default is false ->setFileName('file') ->setFileNamePrefix('prefix_') ->setFileNameSuffix('_suffix.jpg'); $uploader->upload();
If you need manual validation based on defined criteria without actually uploading the file, you can call:
$validation = $uploader->validate(); // true or false
Deleting Files
You can delete files using the delete method. It takes the file path as a parameter.
use Vista\Upload\FileUploader; $uploader = new FileUploader(); $success = $uploader->delete(__DIR__ '/path/to/file.jpg'); // returns true or false
Additional Methods
getResults- Returns the upload results.
[
[
'filename' => 'file.jpg',
'destination' => '/path/to/uploads/file.jpg',
]
]
getErrors- Returns the upload errors.
[
'File type not allowed text/plain',
]
getOriginalFilename- Returns the original file name.
file.txt
getOriginalExtension- Returns the original file extension.
txt
统计信息
- 总下载量: 49
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-25