[英]upload images in “webroot/img” folder in cake php
"I want to upload images in webroot/img folder in cake php.but i am not able to suggest me some solution as i am new to cake php.I tried a lot of solutions from my side but nothing works.so help me" “我想将图像上传到蛋糕php的webroot / img文件夹中,但由于我是蛋糕php的新手,所以我无法向我建议一些解决方案。我尝试了很多解决方案,但没有用,所以请帮帮我。”
my HomesController.php code as
public function admin_add() {
if ($this->request->is('post')) {
$this->Home->create();
$image = $this->request->data['Home']['image'];
//$imageTypes = array("image/gif", "image/jpeg", "image/png");
//$uploadFolder = "upload";
//$uploadPath = WWW_ROOT . $uploadFolder;
pr($this->request->data);
//echo $image['type'];
if ($this->Home->save($this->request->data)) {
$this->Session->setFlash(__('The home has been saved.'));
//echo pr($this->request->data);
//echo die(debug($this->request->data));
//return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The home could not be saved., tryagain '));
}
}
}
admin_add.ctp code is admin_add.ctp代码是
<div class="homes form">
<?php echo $this->Form->create('Home', array('type' => 'file')); ?>
<fieldset>
<legend><?php echo __('Add Home content'); ?></legend>
<?php
echo $this->Form->input('title');
echo $this->Form->input('body');
echo $this->Form->input('image');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit'));
?>
</div>
Blockquote
块引用
whilr running code i am not able to upload images and while printing image data I m getting error. 运行代码时,我无法上传图像,而在打印图像数据时出现错误。
Output:
`Array
(
[Home] => Array
(
[title] => vhbk
[body] => ,bjljbl.
[image] => Array
(
[name] => DSC03371.JPG
[type] =>
[tmp_name] =>
[error] => 1
[size] => 0
)
)
)`
Please refer this : http://www.w3schools.com/php/php_file_upload.asp 请参考: http : //www.w3schools.com/php/php_file_upload.asp
Need to check below things: 需要检查以下内容:
You can also use $_SERVER['DOCUMENT_ROOT'] to change path in above function. 您也可以使用$ _SERVER ['DOCUMENT_ROOT']更改上述功能中的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.