使用cakephp 1.3上传图像
如何创建上载图像功能?一旦上传图像,用户访问主页,图像将显示在主页中,类似于使用cakephp框架的facebook 是否有我可以遵循或指导的示例使用cakephp 1.3上传图像,php,cakephp,cakephp-1.3,Php,Cakephp,Cakephp 1.3,如何创建上载图像功能?一旦上传图像,用户访问主页,图像将显示在主页中,类似于使用cakephp框架的facebook 是否有我可以遵循或指导的示例 谢谢。只需在控制器的add()函数中添加类似的内容即可 // File functions if ($this->data['MODELNAME']['FILENAME']) { $file = new File($this->data['MODELNAME']['FILENAME']['tmp_name'
谢谢。只需在控制器的add()函数中添加类似的内容即可
// 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();
//}
}
只需在控制器的add()函数中添加类似的内容
// 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();
//}
}
你问之前没有查过面包店或谷歌
(谷歌搜索我的第一个结果)你问之前没有检查面包店或谷歌 (我在谷歌搜索的第一个结果)查看,它也有很好的文档记录。查看,它也有很好的文档记录