小编ama*_*k14的帖子

在Cakephp 3.3中上传文件

我想在cakephp 3.0中存储一个图像.我只能在db中保存文件名,但无法将实际文件存储在服务器上.需要帮忙

形成:

        echo $this->Form->create('User', array('url' => array('action' => 'create'), 'enctype' => 'multipart/form-data'));
        echo $this->Form->input('upload', array('type' => 'file'));
Run Code Online (Sandbox Code Playgroud)

图像控制器:

 */
public function add()
{
    $image = $this->Images->newEntity();
    //Check if image has been uploaded
    if(!empty($this->request->data['Images']['upload']['name']))
    {
        $file = $this->request->data['Images']['upload']; //put the data into a var for easy use

        $ext = substr(strtolower(strrchr($file['name'], '.')), 1); //get the extension
        $arr_ext = array('jpg', 'jpeg', 'gif'); //set allowed extensions

        //only process if the extension is valid
        if(in_array($ext, $arr_ext))
        {
            //do the actual uploading of the file. …
Run Code Online (Sandbox Code Playgroud)

cakephp image save cakephp-3.0

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

cakephp ×1

cakephp-3.0 ×1

image ×1

save ×1