Codeigniter 代码点火器:Can';上传后无法从文件夹中获取图像
我刚刚学习了codeigniter,我找到了一些上传和从文件夹中获取图像的教程,函数do_upload()可以工作并创建目录,但函数get_images()不能工作 这是我的模型:Codeigniter 代码点火器:Can';上传后无法从文件夹中获取图像,codeigniter,Codeigniter,我刚刚学习了codeigniter,我找到了一些上传和从文件夹中获取图像的教程,函数do_upload()可以工作并创建目录,但函数get_images()不能工作 这是我的模型: var $gallery_path; var $gallery_path_url; function Gallery_model() { $this->gallery_path = realpath(APPPATH .'../images');
var $gallery_path;
var $gallery_path_url;
function Gallery_model()
{
$this->gallery_path = realpath(APPPATH .'../images');
$this->gallery_path_url = base_url().'images/';
}
function get_images(){
$files = scandir($this->gallery_path.'thumbs');
$files = array_diff($files, array('.', '..', 'thumbs'));
$images = array();
foreach ($files as $file){
$images[] = array(
'url' => $this->gallery_path_url . $file,
'thumb_url' => $this->gallery_path_url . 'thumbs/' . $file
);
}
}
控制器:
function index()
{
$this->load->model('gallery_model');
if($this->input->post('upload')){
$this->gallery_model->do_upload();
}
$data['images'] = $this->gallery_model->get_images();
$this->load->view("gallery", $data);
}
视图:
请上传一张图片
当你说它不起作用时,你是什么意思?它根本就没有图像?走错了路?图像数量错误?请说得更具体些,它根本没有图像。我想是视图或模型有问题,控制器应该正常。好的,你们把图像上传到images文件夹,然后扫描imagesthumbs目录?你们有这样的目录吗?如果有,里面有图像吗?是的,有图像、原始图像和调整大小的图像。一个文件夹是原始图片的图片,第二个文件夹是调整大小的图片的拇指哦对不起,我解决了一个问题。问题在模型中。我需要在最后返回$images
<div id="gallery">
<?php if(isset($images) && count($images)):
foreach ($images as $image):
?>
<div class="thumb">
<a href="<?php echo $image['url']; ?>">
<img src="<?php echo $image['thumb_url']; ?>" />
</a>
</div>
<?php endforeach; else: ?>
<div id="blank_gallery">Please upload an image</div>
<?php endif; ?>
</div>
<div id="upload">
<?php
echo form_open_multipart('gallery');
echo form_upload('userfile');
echo form_submit('upload', 'Upload');
echo form_close();
?>
</div>