开发者

Image upload using cakephp 1.3

开发者 https://www.devze.com 2023-03-28 04:52 出处:网络
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 c

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?

Is there an example which I can follow or guide?

Thank you.


Check out the meio upload behaviour, it's pretty well documented too.


Just add something like this to your controller's 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)

0

精彩评论

暂无评论...
验证码 换一张
取 消