我正在尝试通过编辑图片页面编辑图片,我收到此错误消息:
遇到PHP错误
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/editslideshows.php
Line Number: 86
Backtrace:
File: C:\Program Files\EasyPHP-Devserver-16.1\eds-www\companygiondaci\application\views\editslideshows.php
Line: 86
Function: _error_handler
File: C:\Program Files\EasyPHP-Devserver-16.1\eds-www\companygiondaci\application\controllers\Cuploadfile.php
Line: 81
Function: view
File: C:\Program Files\EasyPHP-Devserver-16.1\eds-www\companygiondaci\index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: image
Filename: views/editslideshows.php
Line Number: 94
Backtrace:
File: C:\Program Files\EasyPHP-Devserver-16.1\eds-www\companygiondaci\application\views\editslideshows.php
Line: 94
Function: _error_handler
File: C:\Program Files\EasyPHP-Devserver-16.1\eds-www\companygiondaci\application\controllers\Cuploadfile.php
Line: 81
Function: view
File: C:\Program Files\EasyPHP-Devserver-16.1\eds-www\companygiondaci\index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: views/editslideshows.php
Line Number: 94
Backtrace:
File: C:\Program Files\EasyPHP-Devserver-16.1\eds-www\companygiondaci\application\views\editslideshows.php
Line: 94
Function: _error_handler
File: C:\Program Files\EasyPHP-Devserver-16.1\eds-www\companygiondaci\application\controllers\Cuploadfile.php
Line: 81
Function: view
File: C:\Program Files\EasyPHP-Devserver-16.1\eds-www\companygiondaci\index.php
Line: 315
Function: require_once
------------------------------
views\editslideshows.php
Line 86: <?php foreach ($images as $image): ?>
Line 94: <?php echo $image->slideshow_image; ?>
此外,在我按下“上传文件”后,它会添加更多图片而不是编辑或替换我期望的旧图片。
我想知道为什么?
控制器/ Cuploadfile.php
function uploadedit()
{
//set preferences
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'jpg|gif';
$config['max_size'] = '500000';
//load upload class library
$this->load->library('upload', $config);
$this->load->model('Mpages');
if (!$this->upload->do_upload('filename'))
{
// case - failure
$upload_error = array('error' => $this->upload->display_errors());
$this->load->view('addslideshows', $upload_error);
}
else
{
// case - success
$upload_data = $this->upload->data();
$filename = $upload_data['file_name'];
$image_id = $this->uri->segment(3);
$data['images'] = $this->Mpages->edit_slideshow($filename, $image_id);
$data['success_msg'] = '<div class="alert alert-success text-center">Your file <strong>' . $upload_data['file_name'] . '</strong> was successfully uploaded!</div>';
$this->load->view('editslideshows', $data);
}
}
视图/ editslideshows.php
<?php foreach ($images as $image): ?>
<img src="<?php echo base_url('uploads/'.$image->slideshow_image); ?>" height="150" width="300">
<?php endforeach; ?>
<br><br>
<?php echo $image->slideshow_image; ?>
模型/ Mpages.php
public function edit_slideshow($filename, $image_id)
{
$this->db->set('slideshow_image', $filename);
$this->db->where('image_id', $image_id);
return $this->db->update('slideshow');
}