fabiopeiva / file-storage
DoctrineORM 实体,用于存储 ZF2 文件
dev-master
2014-10-29 02:30 UTC
Requires
- php: >=5.3.3
- doctrine/doctrine-orm-module: >=0.7.0
This package is not auto-updated.
Last update: 2024-09-24 08:22:50 UTC
README
安装
Composer
php composer.phar require "fabiopaiva/file-storage": "dev-master"
GIT
cd vendor
git clone https://github.com/fabiopaiva/FileStorage
启用模块
application.config.php
<?php
return array(
'modules' => array(
'DoctrineModule',
'DoctrineORMModule',
'FileStorage',
'Application',
),
...
?>
在数据库中创建表
vendor/bin/doctrine-module orm:schema-tool:update --dump-sql
# copy the generated sql and execute in your database for productions environment
# or force to execute into your database directly
vendor/bin/doctrine-module orm:schema-tool:update --force
创建一个可写文件夹
mkdir public/fileStorage
chmod 777 public/fileStorage
您可以在表单构造中设置另一个文件夹
保护此文件夹
强烈建议保护此文件夹。如果您使用 Apache,请在此文件夹中创建一个名为 .htaccess 的文件,内容如下
php_flag engine off
Options -indexes
用法
在您的实体中
/**
* @ORM\ManyToOne(targetEntity="\FileStorage\Entity\Document", cascade={"persist", "remove"})
* @var \FileStorage\Entity\Document
*/
protected $myFile;
辅助工具
使用 route-file-storage 管理文件
<?php echo $this->url('file-storage');?>
使用 downloadLink 方法获取文件路径
<?php echo $document->getDownloadLink();?>