多个图像编辑错误在我的cakephp项目。 cakephp2.5 [英] multiple image editing error in my cakephp project. cakephp2.5
问题描述
当我更新所有3个图像,那么它会工作正常。
如果我不更新所有3,那么它的工作正常。但它不会工作,如果我更新1而不是其他。即使它不会工作,如果我更新2而不是1。可能是它的我的if else cond。错误。但我无法想象出来。所以plz帮我感谢:)
public function edit($ id = 2){
$ this-> helpers = array('TinyMCE.TinyMCE');
$ this-> layout ='adminpanel';
if(!$ id){
throw new NotFoundException(__('Invalid post'));
}
$ this-> layout ='adminpanel';
//保存数据
if($ this-> request-> is(array('post','put'))){
$ this-> ; Home-> id = $ id;
//保存图片
if(is_uploaded_file($ this-> request-> data ['Home'] ['image_1'] ['tmp_name']))
{
$ fileNameFull = $ this-> request-> data ['Home'] ['image_1'] ['name'];
$ uploadFolder =upload;
//上传文件夹的完整路径
$ uploadPath = WWW_ROOT。 $ uploadFolder;
$ oldFile = $ uploadPath。'/'。$ fileNameFull;
move_uploaded_file(
$ this-> request-> data ['Home'] ['image_1'] ['tmp_name'],$ oldFile
);
$ newFile = WWW_ROOT.'courseImages / thumb /'.$ fileNameFull;
$ image = new ImageResizeComponent();
$ quality = 100; // image resize for thumb
$ height = 40;
$ width = 60;
$ this-> ImageResize-> resize($ oldFile,$ newFile,60,60,$ quality);
$ this-> request-> data ['Home'] ['image_1'] = $ fileNameFull;
}
if(is_uploaded_file($ this-> request-> data ['Home'] ['image_3'] ['tmp_name']))
{
$ fileNameFull = $ this-> request-> data ['Home'] ['image_3'] ['name'];
$ uploadFolder =upload;
//上传文件夹的完整路径
$ uploadPath = WWW_ROOT。 $ uploadFolder;
$ oldFile = $ uploadPath。'/'。$ fileNameFull;
move_uploaded_file(
$ this-> request-> data ['Home'] ['image_3'] ['tmp_name'],$ oldFile
);
$ newFile = WWW_ROOT.'courseImages / thumb /'.$ fileNameFull;
$ image = new ImageResizeComponent();
$ quality = 100; // image resize for thumb
$ height = 40;
$ width = 60;
$ this-> ImageResize-> resize($ oldFile,$ newFile,60,60,$ quality);
$ this-> request-> data ['Home'] ['image_3'] = $ fileNameFull;
}
if(is_uploaded_file($ this-> request-> data ['Home'] ['image_2'] ['tmp_name']))
{
$ fileNameFull = $ this-> request-> data ['Home'] ['image_2'] ['name'];
$ uploadFolder =upload;
//上传文件夹的完整路径
$ uploadPath = WWW_ROOT。 $ uploadFolder;
$ oldFile = $ uploadPath。'/'。$ fileNameFull;
move_uploaded_file(
$ this-> request-> data ['Home'] ['image_2'] ['tmp_name'],$ oldFile
);
$ newFile = WWW_ROOT.'courseImages / thumb /'.$ fileNameFull;
$ image = new ImageResizeComponent();
$ quality = 100; // image resize for thumb
$ height = 40;
$ width = 60;
$ this-> ImageResize-> resize($ oldFile,$ newFile,60,60,$ quality);
$ this-> request-> data ['Home'] ['image_2'] = $ fileNameFull;
}
else {// Img未上传
// **两条生命线的黄金线**
$ tourForImg = $ this->首页 - > findByid($ id);
$ this-> request-> data ['Home'] ['image_1'] = $ tourForImg ['Home'] ['image_1'];
$ this-> request-> data ['Home'] ['image_2'] = $ tourForImg ['Home'] ['image_2'];
$ this-> request-> data ['Home'] ['image_3'] = $ tourForImg ['Home'] ['image_3'];
// **您的生活的两条黄金线**
}
if($ this-> Home-> save($ this-> request-> data)){
$ this-> Session-> setFlash(__('无法hppp,例如你的日程安排。
//保存图片
$ this-> Session-> setFlash('Your home slider image has been saved343434。','default',array('class'=> 'alert alert-success'));
// $ this-> Session-> setFlash(__('Your home is been updated。'));
return $ this-> redirect(array('controller'=>'homes','action'=>'edit'));
$ this-> Session-> setFlash(__('无法更新您的游览。
}
}
$ home = $ this-> Home-> findByid($ id);
if(!$ home){
throw new NotFoundException(__('Invalid post'));
}
if(!$ this-> request-> data){
$ this-> request-> data = $ home;
}
}
echo $ this-> Form-> create('Home',array('autocomplete'=>'off','enctype'=>'multipart / form-data' ));
echo $ this-> Form-> input('image_1',array('type' '文件'));
//然后显示图像
//上面相同的3图像
code> echo $ this-> Form-> input('id',array('type'=>'hidden'))
echo $ this-> Form-> end('Save Post');
?>
使用AND运算符
if(is_uploaded_file($ this-> request-> data ['Home'] ['image_1'] ['tmp_name'])&&
is_uploaded_file - > request-> request [> data ['Home'] ['image_3'] ['tmp_name'])&&
is_uploaded_file($ this-> request-> data ['Home' 'image_2'] ['tmp_name'])
)
{
//这里的代码为所有3图像u你写在上面的代码全部代码
//保存图像
$ fileNameFull = $ this-> request-> data ['Home'] ['image_1'] ['name'];
$ uploadFolder =upload;
//上传文件夹的完整路径
$ uploadPath = WWW_ROOT。 $ uploadFolder;
$ oldFile = $ uploadPath。'/'。$ fileNameFull;
move_uploaded_file(
$ this-> request-> data ['Home'] ['image_1'] ['tmp_name'],$ oldFile
);
$ newFile = WWW_ROOT.'courseImages / thumb /'.$ fileNameFull;
$ image = new ImageResizeComponent();
$ quality = 100; // image resize for thumb
$ height = 40;
$ width = 60;
$ this-> ImageResize-> resize($ oldFile,$ newFile,60,60,$ quality);
$ this-> request-> data ['Home'] ['image_1'] = $ fileNameFull;
$ fileNameFull = $ this-> request-> data ['Home'] ['image_3'] ['name'];
$ uploadFolder =upload;
//上传文件夹的完整路径
$ uploadPath = WWW_ROOT。 $ uploadFolder;
$ oldFile = $ uploadPath。'/'。$ fileNameFull;
move_uploaded_file(
$ this-> request-> data ['Home'] ['image_3'] ['tmp_name'],$ oldFile
);
$ newFile = WWW_ROOT.'courseImages / thumb /'.$ fileNameFull;
$ image = new ImageResizeComponent();
$ quality = 100; // image resize for thumb
$ height = 40;
$ width = 60;
$ this-> ImageResize-> resize($ oldFile,$ newFile,60,60,$ quality);
$ this-> request-> data ['Home'] ['image_3'] = $ fileNameFull;
$ fileNameFull = $ this-> request-> data ['Home'] ['image_2'] ['name'];
$ uploadFolder =upload;
//上传文件夹的完整路径
$ uploadPath = WWW_ROOT。 $ uploadFolder;
$ oldFile = $ uploadPath。'/'。$ fileNameFull;
move_uploaded_file(
$ this-> request-> data ['Home'] ['image_2'] ['tmp_name'],$ oldFile
);
$ newFile = WWW_ROOT.'courseImages / thumb /'.$ fileNameFull;
$ image = new ImageResizeComponent();
$ quality = 100; // image resize for thumb
$ height = 40;
$ width = 60;
$ this-> ImageResize-> resize($ oldFile,$ newFile,60,60,$ quality);
$ this-> request-> data ['Home'] ['image_2'] = $ fileNameFull;
//这里3 img
}
else if(is_uploaded_file($ this-> request-> data ['Home'] ['image_1' ] ['tmp_name'])&&
is_uploaded_file($ this-> request-> data ['Home'] ['image_3'] ['tmp_name'])
)
{
//此处的代码为'image_1`和`image_3`
}
else if(is_uploaded_file($ this-> request-> data ['Home '] ['image_1'] ['tmp_name'])&&
is_uploaded_file($ this-> request-> data ['Home'] ['image_2'] ['tmp_name'])
)
{
//这里的代码为`image_1`和`image_2`
}
else if(is_uploaded_file($ this-> request-> data [ 'home'] ['image_2'] ['tmp_name']'''''''['home'] ['image_3'] ['tmp_name'])&& )
)
{
//这里的代码为'image_3`和`image_2`
}
else if(is_uploaded_file($ this-> request->数据['Home'] ['image_1'] ['tmp_name']))
{
//此处的代码为`image_1`
}
else if(is_uploaded_file this-> request-> data ['Home'] ['image_2'] ['tmp_name']))
{
//此处的代码为`image_2`
}
else if(is_uploaded_file($ this-> request-> data ['Home'] ['image_3'] ['tmp_name']))
{
// HERE Code FOR`image_3 `
}
else {// Img未上传
//此处您的部分您有WHEN图像未上传
}
//根据您的问题更新 - >
查看第一个ELSE IF:
else if(is_uploaded_file($ this-> request-> data ['Home'] ['image_1'] ['tmp_name'])& ;&
is_uploaded_file($ this-> request-> data ['Home'] ['image_3'] ['tmp_name'])
)
{
// hav值为image_1和image_3确定? BUT`image_2`val missing.SO从数据库设置OLD VALUE
$ tourForImg = $ this-> Home-> findByid($ id);
$ this-> request-> data ['Home'] ['image_2'] = $ tourForImg ['Home'] ['image_2'];
}
现在对于下一个
else if(is_uploaded_file请求 - >数据['Home'] ['image_1'] ['tmp_name'])&&
is_uploaded_file($ this-> request-> data ['Home'] ['image_2'] [ tmp_name'])
)
{
//现在可用于 image_1
AND image_2
OK? BUT image_3
val missing.SO从数据库设置OLD VALUE
$ tourForImg = $ this-> Home-> findByid($ id);
$ this-> request-> data ['Home'] ['image_3'] = $ tourForImg ['Home'] ['image_3'];
}
同样FOR>如果 image1仅上传
然后设置
OLD image2& image3 from DATABASE
只对上传的image2执行相同操作
GETTNG?使用自己的逻辑dude。
when i update all 3 images then it will work fine. if i dont update all 3 then its work fine . but it will not work if i update 1 and not other. even it will not work if i update 2 and not 1 . may be its my if else cond. error. but i cant fig it out. so plz help me thanks :)
public function edit($id=2) {
$this->helpers = array('TinyMCE.TinyMCE');
$this->layout = 'adminpanel';
if (!$id) {
throw new NotFoundException(__('Invalid post'));
}
$this->layout = 'adminpanel';
//save data
if ($this->request->is(array('post', 'put'))) {
$this->Home->id = $id;
//Save image
if(is_uploaded_file($this->request->data['Home']['image_1']['tmp_name']))
{
$fileNameFull = $this->request->data['Home']['image_1']['name'];
$uploadFolder = "upload";
//full path to upload folder
$uploadPath = WWW_ROOT . $uploadFolder;
$oldFile = $uploadPath.'/'.$fileNameFull;
move_uploaded_file(
$this->request->data['Home']['image_1']['tmp_name'],$oldFile
);
$newFile = WWW_ROOT.'courseImages/thumb/'.$fileNameFull;
$image = new ImageResizeComponent();
$quality = 100; // image resize for thumb
$height = 40;
$width = 60;
$this->ImageResize->resize($oldFile, $newFile, 60,60,$quality);
$this->request->data['Home']['image_1'] = $fileNameFull;
}
if(is_uploaded_file($this->request->data['Home']['image_3']['tmp_name']))
{
$fileNameFull = $this->request->data['Home']['image_3']['name'];
$uploadFolder = "upload";
//full path to upload folder
$uploadPath = WWW_ROOT . $uploadFolder;
$oldFile = $uploadPath.'/'.$fileNameFull;
move_uploaded_file(
$this->request->data['Home']['image_3']['tmp_name'],$oldFile
);
$newFile = WWW_ROOT.'courseImages/thumb/'.$fileNameFull;
$image = new ImageResizeComponent();
$quality = 100; // image resize for thumb
$height = 40;
$width = 60;
$this->ImageResize->resize($oldFile, $newFile, 60,60,$quality);
$this->request->data['Home']['image_3'] = $fileNameFull;
}
if(is_uploaded_file($this->request->data['Home']['image_2']['tmp_name']))
{
$fileNameFull = $this->request->data['Home']['image_2']['name'];
$uploadFolder = "upload";
//full path to upload folder
$uploadPath = WWW_ROOT . $uploadFolder;
$oldFile = $uploadPath.'/'.$fileNameFull;
move_uploaded_file(
$this->request->data['Home']['image_2']['tmp_name'],$oldFile
);
$newFile = WWW_ROOT.'courseImages/thumb/'.$fileNameFull;
$image = new ImageResizeComponent();
$quality = 100; // image resize for thumb
$height = 40;
$width = 60;
$this->ImageResize->resize($oldFile, $newFile, 60,60,$quality);
$this->request->data['Home']['image_2'] = $fileNameFull;
}
else{//Img not uploaded
//**TWO GOLDEN LINES OF YOUR LIFE**
$tourForImg = $this->Home->findByid($id);
$this->request->data['Home']['image_1'] = $tourForImg['Home']['image_1'];
$this->request->data['Home']['image_2'] = $tourForImg['Home']['image_2'];
$this->request->data['Home']['image_3'] = $tourForImg['Home']['image_3'];
//**TWO GOLDEN LINES OF YOUR LIFE**
}
if ($this->Home->save($this->request->data)) {
$this->Session->setFlash(__('Unable to hppp,ee your schedule.'));
//Save image
$this->Session->setFlash('Your home slider image has been saved343434.', 'default',array('class' => 'alert alert-success'));
//$this->Session->setFlash(__('Your home has been updated.'));
return $this->redirect(array('controller'=>'homes','action' => 'edit'));
$this->Session->setFlash(__('Unable to update your Tour.'));
}
}
$home = $this->Home->findByid($id);
if (!$home) {
throw new NotFoundException(__('Invalid post'));
}
if (!$this->request->data) {
$this->request->data = $home;
}
}
echo $this->Form->create('Home',array('autocomplete' => 'off','enctype'=>'multipart/form-data'));
echo $this->Form->input('image_1', array('type' => 'file')); // then display images
//above same for 3 image
echo $this->Form->input('id', array('type' => 'hidden'));
echo $this->Form->end('Save Post'); ?>
use AND operator
if(is_uploaded_file($this->request->data['Home']['image_1']['tmp_name']) &&
is_uploaded_file($this->request->data['Home']['image_3']['tmp_name']) &&
is_uploaded_file($this->request->data['Home']['image_2']['tmp_name'])
)
{
//HERE Code FOR ALL 3 IMAGES u You have written in the above code WHOLE CODE
//Save image
$fileNameFull = $this->request->data['Home']['image_1']['name'];
$uploadFolder = "upload";
//full path to upload folder
$uploadPath = WWW_ROOT . $uploadFolder;
$oldFile = $uploadPath.'/'.$fileNameFull;
move_uploaded_file(
$this->request->data['Home']['image_1']['tmp_name'],$oldFile
);
$newFile = WWW_ROOT.'courseImages/thumb/'.$fileNameFull;
$image = new ImageResizeComponent();
$quality = 100; // image resize for thumb
$height = 40;
$width = 60;
$this->ImageResize->resize($oldFile, $newFile, 60,60,$quality);
$this->request->data['Home']['image_1'] = $fileNameFull;
$fileNameFull = $this->request->data['Home']['image_3']['name'];
$uploadFolder = "upload";
//full path to upload folder
$uploadPath = WWW_ROOT . $uploadFolder;
$oldFile = $uploadPath.'/'.$fileNameFull;
move_uploaded_file(
$this->request->data['Home']['image_3']['tmp_name'],$oldFile
);
$newFile = WWW_ROOT.'courseImages/thumb/'.$fileNameFull;
$image = new ImageResizeComponent();
$quality = 100; // image resize for thumb
$height = 40;
$width = 60;
$this->ImageResize->resize($oldFile, $newFile, 60,60,$quality);
$this->request->data['Home']['image_3'] = $fileNameFull;
$fileNameFull = $this->request->data['Home']['image_2']['name'];
$uploadFolder = "upload";
//full path to upload folder
$uploadPath = WWW_ROOT . $uploadFolder;
$oldFile = $uploadPath.'/'.$fileNameFull;
move_uploaded_file(
$this->request->data['Home']['image_2']['tmp_name'],$oldFile
);
$newFile = WWW_ROOT.'courseImages/thumb/'.$fileNameFull;
$image = new ImageResizeComponent();
$quality = 100; // image resize for thumb
$height = 40;
$width = 60;
$this->ImageResize->resize($oldFile, $newFile, 60,60,$quality);
$this->request->data['Home']['image_2'] = $fileNameFull;
//Here 3 img
}
else if(is_uploaded_file($this->request->data['Home']['image_1']['tmp_name']) &&
is_uploaded_file($this->request->data['Home']['image_3']['tmp_name'])
)
{
//HERE Code FOR `image_1` AND `image_3`
}
else if(is_uploaded_file($this->request->data['Home']['image_1']['tmp_name']) &&
is_uploaded_file($this->request->data['Home']['image_2']['tmp_name'])
)
{
//HERE Code FOR `image_1` AND `image_2`
}
else if(is_uploaded_file($this->request->data['Home']['image_3']['tmp_name']) &&
is_uploaded_file($this->request->data['Home']['image_2']['tmp_name'])
)
{
//HERE Code FOR `image_3` AND `image_2`
}
else if(is_uploaded_file($this->request->data['Home']['image_1']['tmp_name']))
{
//HERE Code FOR `image_1`
}
else if(is_uploaded_file($this->request->data['Home']['image_2']['tmp_name']))
{
//HERE Code FOR `image_2`
}
else if(is_uploaded_file($this->request->data['Home']['image_3']['tmp_name']))
{
//HERE Code FOR `image_3`
}
else{//Img not uploaded
//HERE YOUR part You had WHEN image is NOT Uploaded
}
//Updated as per Your issue-> SEE , check 1st ELSE IF :
else if(is_uploaded_file($this->request->data['Home']['image_1']['tmp_name']) &&
is_uploaded_file($this->request->data['Home']['image_3']['tmp_name'])
)
{
//NOW u hav VALUES FOR `image_1` AND `image_3` OK ? BUT `image_2` val missing.SO set OLD VALUE from database
$tourForImg = $this->Home->findByid($id);
$this->request->data['Home']['image_2'] = $tourForImg['Home']['image_2'];
}
Now for next
else if(is_uploaded_file($this->request->data['Home']['image_1']['tmp_name']) &&
is_uploaded_file($this->request->data['Home']['image_2']['tmp_name'])
)
{
//NOW u hav VALUES FOR image_1
AND image_2
OK ? BUT image_3
val missing.SO set OLD VALUE from database
$tourForImg = $this->Home->findByid($id);
$this->request->data['Home']['image_3'] = $tourForImg['Home']['image_3'];
}
DO SAME FOR -> if image1 is only uploaded
Then set
OLD values of image2 & image3 from DATABASE
Do same for image2 only uploaded
Do same for image3 only uploaded .
GETTNG? use your own logic dude.
这篇关于多个图像编辑错误在我的cakephp项目。 cakephp2.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!