jdavidbakr/upload-aws

此包已被废弃,不再维护。作者建议使用intervention/image包代替。

一个管理文件上传并将文件发送到AWS的服务。包括几个图像处理功能。

1.0.4 2016-01-08 19:05 UTC

This package is auto-updated.

Last update: 2019-09-28 14:28:41 UTC


README

Latest Version on Packagist Software License Total Downloads

一个用于处理图像并将其上传到AWS的包装类。包括如调整大小、裁剪等功能。如果需要保留原始文件名,应在数据库中进行操作。这是为了防止远程文件名冲突;类返回随机的远程文件名。

需要PHP-GD库。

这应该在Laravel外部也能工作,但我为Laravel构建了它,所以效果可能因环境而异。

处理上传的文件

// Instantiate with the $_FILE array.
// Uses config('aws.bucket') or you can pass the bucket as the second argument of the constructor.
$upload = new \jdavidbakr\UploadAWS($_FILE['form_name']);

// Retrieve the location of the uploaded file and store it somewhere
$location = $upload->get_location();

处理已上传的文件

// Instantiate with the remote file path
$upload = new \jdavidbakr\UploadAWS($location);

一旦您有了文件,就可以对其进行多种操作,尤其是如果它是一个图像文件

// Get a temporary signed URL
$url = $upload->get_url();
// Resize the image
$upload->resize_image(640,480);
// Resize the image so that it fits in the max size
$upload->get_max_size(1000,1000);
// Scale image, applies pillarbox or letterbox to retain the aspect ratio
$upload->scale_image(640,480);
// Crop the image to this size, will retain the current image center
$upolad->crop_image(640,480);
// Crop the image with full control over what part of the image to keep
$upload->crop($top, $left, $width, $height);
// Copy the image into a new file location
$upload->copy();
// Delete the remote file
$upload->delete();
// Get the actual size of the file
$upload->get_file_size();