简体   繁体   中英

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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