简体   繁体   English

图片上传使用cakephp 1.3

[英]Image upload using cakephp 1.3

How do you create an upload image feature?如何创建上传图片功能? and once the image has been uploaded and the user access the homepage, the image will be display in the homepage similar to facebook using cakephp framework?并且一旦图像被上传并且用户访问主页,图像将显示在主页中,类似于使用 cakephp 框架的 facebook?

Is there an example which I can follow or guide?有没有我可以遵循或指导的例子?

Thank you.谢谢你。

Check out the meio upload behaviour , it's pretty well documented too.查看meio 上传行为,它也有很好的记录。

Just add something like this to your controller's add() function.只需在控制器的 add() function 中添加类似的内容。

    // File functions
    if ($this->data['MODELNAME']['FILENAME']) {
        $file = new File($this->data['MODELNAME']['FILENAME']['tmp_name']);
        $ext = $this->data['MODELNAME']['FILENAME']['name'];
        $point = strrpos($ext,'.');
        $ext = substr($ext,$point+1,(strlen($ext)-$point));

        /*if ($ext != 'jpg' && $ext != 'jpeg' && $ext != 'gif' && $ext != 'png') {
            $this->Session->setFlash('You may only upload image files.');
            $this->render();
        } else {*/
        $filename = 'filename.'.$ext;
        $data = $file->read();
        $file->close();
        $file = new File(WWW_ROOT.'/img/'.$filename,true);
        $file->write($data);
        $file->close();
        //}
    }

You didn't check the bakery or Google before asking?你问之前没有检查面包店或谷歌吗?

Anyway try this out (the first result in a Google search for me) 无论如何试试这个(谷歌搜索我的第一个结果)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM