function package_edit($id = null) {
$this->layout = 'admin';
$this->loadModel('Package');
$this->Package->id = $id;
if (empty($this->data)) {
$this->data = $this->Package->read();
} else {
if(!empty ($this->request->data)) {
$package_data = $this->request->data['Package'];
$image = array();
$formimage = array('images','images1');
$image = array($package_data['images'],$package_data['images1']);
$file = $this->uploadFiles('img/package', $image,$formimage);
print_r($file); /* check file upload */
if(!isset($file['urls'])) {
$this->Session->setFlash(implode($file['errors']));
} else {
for($i=0; $i < count($file['urls']); $i++) {
$package_data[$formimage[$i]] = $file['urls'][$formimage[$i]];
}
}
}
if($package_data['images']['error'] == 4) {
unset($package_data['images']);
}
if($package_data['images1']['error'] == 4) {
unset($package_data['images1']);
}
if ($this->Package->save($package_data)) {
$this->Session->setFlash('Your package has been updated.');
$this->redirect(array('action'=>'package_list'));
} else {
$this->Session->setFlash('Your package Not updated.');
$this->redirect(array('action'=>'package_list'));
}
}
}
这是我的代码,在这种情况下我上传了两张图片:
- 如果我无法上传任何图像,编辑功能可以正常工作
- 如果我更新第一个图像,它可以正常工作
- 最后,如果我不更新第一张图片,我只会更新第二张图片,它会显示错误
错误:
Array (
[price] => 25
[no_of_peeks] => 22
[package_title] => gfhgfh
[package_desc] => gfhhgfgfh
[featured] => 0
[images] =>
[images1] =>
Array (
[name] => itunes_gift_card_hack.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpBrIadh
[error] => 0
[size] => 84925
)
)
请帮忙?