sevens/uploader-trait

PHP 文件上传库。

v1.0.0 2020-11-14 00:54 UTC

This package is auto-updated.

Last update: 2024-09-26 21:34:21 UTC


README

- It is part of the libraries used on the altvel framework project but can be used 
in any applicable file upload scenario.

- File Uploader a.k.a uploader-trait is developed by Elisha Temiloluwa a.k.a TemmyScope.

- Developed to make easier the routine of file upload on traditional file servers.


- Install using composer
composer require sevens/uploader-trait

使用:实现与扩展

您可以使用两种方式在项目中使用此库

- One way would be to call the Uploader constructor
use Seven\File\Uploader;

$uploader = new Uploader(
 string $destination = __DIR__.'/cdn', 
 array $allowedTypes = [ 'jpg' => 'image/jpeg', 'png' => 'image/png' ],
 int $sizeLimit =  5024768
);

$uploader->upload('image');
- Another way would be to extend the Uploader Class and provide the necessary properties

***如果您没有提供必要的属性,上传器类中已经提供了默认值 ***

use Seven\File\Uploader;

class FileUploader extends Uploader{

 protected $destination = __DIR__.'/cdn';

 protected $allowedTypes = [ 'jpg' => 'image/jpeg', 'png' => 'image/png' ];

 protected $sizeLimit =  5024768;

}

使用:调用方法

此库中有几个有用的方法可以使用

	$file = new FileUploader();
- Upload $_FILES['image']
$file->upload('image'); 
- To get uploaded file name only
$file->name()
- To get uploaded file address, containing file address and name
$file->fullName(); 
- To get uploaded file type
$file->type();
- To get uploaded status; returns True if upload was successful
$file->status();
- To get error message; it would be empty if upload status is true
$file->statusMessage();