我正在使用cakephp uploader 4.3.1
中的milesj.me
插件。我使用composer
正常工作来安装它。
现在的问题是,当我上传图像时,一个条目被添加到数据库中,带有图像路径,但我找不到目标文件夹中的图像。
Model->save
函数正在成功执行。
我正在使用cakephp 2x
修改
如果我不给目标目录,文件将被上传到/files/uploads
目录,我可以在那里找到图像!!!!!!!!!!
但是当我将目标作为/img/uploads
时,我找不到。
型号代码
CustomImage.php
<?php
App::uses('AppModel', 'Model');
class CustomImage extends AppModel
{
public $name = 'CustomImage';
public $actsAs = array(
'Uploader.Attachment' => array(
'upload_image' => array(
'uploadDir' => '/img/uploads/',
'finalPath' => '/img/uploads/',
'dbColumn' => 'path',
'maxNameLength' => 30,
'overwrite' => true,
'stopSave' => true,
'allowEmpty' => false,
'transforms' => array(
array('method' => 'resize', 'width' => 240, 'dbColumn' => 'photo_thumb'))
)
),
'Uploader.FileValidation' => array(
'upload_image' => array(
'extension' => array('gif', 'jpg', 'png', 'jpeg'),
'required' => true
)
)
);
}
?>
控制器代码
MotionMakerController.php
class MotionMakerController extends AppController
{
public $helpers = array('Html','Form');
public $uses = array('CustomImage');
public function index()
{
}
public function add() {
if ($this->CustomImage->save($this->request->data, true)) {
echo "success";
}
}
}
查看代码
add.ctp
<?php
echo $this->Form->create('CustomImage', array('type' => 'file'));
echo $this->Form->input('upload_image', array('type' => 'file'));
echo $this->Form->end('Submit');
?>
请帮帮我。
答案 0 :(得分:1)
尝试创建全局变量并将其替换为“/ img / uploads /”。 例如:
define('UPLOAD_DIR',WWW_ROOT。'/ img / uploads');