bmcclure / cakephp-media-plugin
CakePHP 媒体插件
dev-cake-2.0 / 2.x-dev
2014-04-18 17:04 UTC
Requires
- php: >=5.2.8
- composer/installers: *
This package is auto-updated.
Last update: 2024-08-29 04:03:23 UTC
README
##数据库字段
create table users ( id char(36) not null, file varchar(255) default null, dirname varchar(255) default null, basename varchar(255) default null, checksum varchar(255) default null, created datetime default null, modified datetime default null, primary key(id) );
##安装
- 克隆到 /path/to/app/Plugin
git clone https://bmcclure@github.com/bmcclure/CakePHP-Media-Plugin.git Media
- 作为子模块添加
git submodule add https://bmcclure@github.com/bmcclure/CakePHP-Media-Plugin.git Plugin/Media
- 加载插件。
``//Within your bootstrap.php`` ``CakePlugin::load('Media', array('bootstrap'=>true));`
- 初始化媒体文件。
cake Media.Media init
--------------------------------------------------------------- Media Shell --------------------------------------------------------------- Do you want to create missing media directories now? [n] > y`` /app/webroot/media/ [OK ] /app/webroot/media/static/ [OK ] /app/webroot/media/static/aud [OK ] /app/webroot/media/static/doc [OK ] /app/webroot/media/static/gen [OK ] /app/webroot/media/static/img [OK ] /app/webroot/media/static/vid [OK ] /app/webroot/media/transfer/ [OK ] /app/webroot/media/transfer/aud [OK ] /app/webroot/media/transfer/doc [OK ] /app/webroot/media/transfer/gen [OK ] /app/webroot/media/transfer/img [OK ] /app/webroot/media/transfer/vid [OK ] /app/webroot/media/filter/ [OK ] Your transfer directory is missing a htaccess file to block requests. Do you want to create it now? [n] > n
- 设置媒体文件夹的权限
chmod -R 777 webroot/media/{transfer,filter}
##上传和查看图片
- 将模型设置为媒体传输用户
````
- 设置表单
``echo $this->Form->create('User', array('type'=>'file'));`` ``echo $this->Form->input('file', array('type'=>'file'));`` ``echo $this->Form->input('dirname', array('type'=>'hidden'));`` ``echo $this->Form->input('basename', array('type'=>'hidden'));`` ``echo $this->Form->input('checksum', array('type'=>'hidden'));`` ``echo $this->Form->end(__('Submit'));``
- 要查看图片,将 Media 辅助器添加到控制器中并使用
``Media->embed(h($employee['User']['basename'])); ?>``
- 享受吧!