cakephp上传插件-定义保存文件的目录
我正在使用jose gonzalez的cakephp上传将图像上传到我们的应用程序。默认情况下,它们被保存在如下目录中:cakephp上传插件-定义保存文件的目录,php,image,cakephp,upload,Php,Image,Cakephp,Upload,我正在使用jose gonzalez的cakephp上传将图像上传到我们的应用程序。默认情况下,它们被保存在如下目录中:webroot/files/user/photo/{user\u id},这很好,但当我们想使用$this->Html->image()在webroot/img目录中搜索图像时除外 我已经尝试使用 echo $this->Html->image('../files/user/photo/' . $user['User']['photo_dir'] .
webroot/files/user/photo/{user\u id}
,这很好,但当我们想使用$this->Html->image()
在webroot/img目录中搜索图像时除外
我已经尝试使用
echo $this->Html->image('../files/user/photo/' .
$user['User']['photo_dir'] . '/' .
$user['User']['photo']);
这是可行的,但我想知道是否有办法告诉这个插件保存到img目录中?文档中没有提到这些
还有,有没有办法告诉$this->Form->input('User.photo',array('type'=>'file')
仅接受图像文件吗?正如您在本文档中看到的,路径设置如下:
public $defaults = array(
'rootDir' => null,
'pathMethod' => 'primaryKey',
'path' => '{ROOT}webroot{DS}files{DS}{model}{DS}{field}{DS}',
...
您可以将其更改为:
'path' => '{ROOT}webroot{DS}img{DS}'
对于第二个问题,可以使用accept
属性,如:
$this->Form->input('User.photo',
array(
'type' => 'file',
'options' => array('accept' => 'image/*')
)
);