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
)
)
请hlp?
答案 0 :(得分:0)
$file = $this->uploadFiles('img/package', $image,$formimage);
print_r($file);
在该行中,看起来您的uploadFiles组件需要一组图像。
由于$package_data['images']
为空且$package_data['images1']
包含图像数据,因此如果图像为空,则应取消设置图像的第一个数组索引。一旦到达数组值为空,组件就可以终止。
如果您在保存功能之前pr($package_data);
并将其粘贴到您的问题中,那么我们也可以看到将数据传递给uploadFiles。或者在发送到uploadFile组件后pr($files);
。