teepluss / up
UP是一个具有多态关系的文件上传器。
v1.0.0
2014-08-28 12:13 UTC
Requires
- php: >=5.3.0
- smottt/wideimage: dev-master
Requires (Dev)
- illuminate/support: 4.1.x
This package is not auto-updated.
Last update: 2024-09-23 15:10:24 UTC
README
UP已弃用。请使用UP2
UP for Laravel 4
UP是一个具有多态关系的文件上传器。
安装
要获取主题的最新版本,只需在您的composer.json
文件中引入它。
"teepluss/up": "dev-master"
然后您需要运行composer install
来下载它并更新自动加载器。
一旦主题安装完毕,您需要将服务提供者注册到应用程序中。打开app/config/app.php
并找到providers
键。
'providers' => array(
'Teepluss\Up\UpServiceProvider'
)
UP还附带了一个门面,提供了创建集合的静态语法。您可以在app/config/app.php
文件的aliases
键中注册门面。
'aliases' => array(
'UP' => 'Teepluss\Up\Facades\Up'
)
使用Artisan CLI发布配置。
php artisan config:publish teepluss/up
迁移表。
php artisan migrate --package=teepluss/up
使用方法
首先,您必须为想要使用"UP"的模型创建一个多态方法。
class Blog extends Eloquent { public function ..... /** * Blog has many files upload. * * @return AttachmentRelate */ public function files() { return $this->morphMany('\Teepluss\Up\AttachmentRelates\Eloquent\AttachmentRelate', 'fileable'); } }
创建方法"files"后,Blog可以使用"UP"来上传文件。
上传文件并进行缩放。
// Return an original file meta. UP::upload(Blog::find(1), Input::file('userfile'))->getMasterResult(); UP::upload(User::find(1), Input::file('userfile'))->getMasterResult(); // Return all results files uploaded including resized. UP::upload(Product::find(1), Input::file('userfile'))->resize()->getResults(); // If you have other fields in table attachments. UP::upload(User::find(1), Input::file('userfile'), array('some_id' => 999))->getMasterResult();
// UP可以上传远程文件。UP::inject(array('remote' => true))->upload(User::find(1), Input::file('userfile'), array('some_id' => 999))->getResults();
查找文件路径。
$blogs = Blog::with('files')->get(); foreach ($blogs as $blog) { foreach ($blog->files as $file) { // Access attachment. // var_dump($file->atatchment); echo UP::lookup($file->attachment_id); // or lookup with scale from config. echo UP::lookup($file->attachment_id)->scale('l'); } }
从存储中删除文件。
$attachmentId = 'b5540d7e6350589004e02e23feb3dc1f'; // Remove a single file. UP::remove($attachmentId); // Remove all files including resized. UP::remove($attachmentId, true);
支持或联系
如果您遇到任何问题,请通过teepluss@gmail.com联系。