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)
精彩评论