Codeigniter权限被拒绝的图像上传 [英] Codeigniter Permission denied images upload

查看:135
本文介绍了Codeigniter权限被拒绝的图像上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何用codeigniter上传一个图像,我得到一个错误权限,当我点击上传没有任何图像,如果我选择一个图像工作得很好。我只是希望它会显示我的消息是:请上传图片,你可以看看我的代码,并帮助我找出我的问题。
错误说:

这是我的查看代码:

i am learning how to upload an image with codeigniter, and i got an error permission denied when i click on the upload without any image, it works well if i select an image. i just hoped it will show my message it is: Please upload an Images,can you have a look on my code and help me figure down my problem. the error says: This is my view code:

<head>
<title>CI upload images</title>
<meta charset="UTF-8">
</head>
<body>
<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 Images</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>
</body>

这是我的控制器代码:

class Gallery extends CI_Controller{
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_view', $data);

}
}

p>

and here is my model

class Gallery_model extends CI_Model{

var $gallery_path;
var $gallery_path_url;

function __construct(){
    parent::__construct();

    $this->gallery_path = realpath(APPPATH . '../images');
    $this->gallery_path_url = base_url().'images/';
}
function do_upload(){
    $config = array(
        'allowed_types' => 'jpg|jpeg|gif|png',
        'upload_path' => $this->gallery_path,
        'max_size' => 2000
        );
    $this->load->library('upload', $config);
    $this->upload->do_upload();
    $image_data = $this->upload->data();

    $config = array(
        'source_image' => $image_data['full_path'],
        'new_image' => $this->gallery_path . '/thumbs',
        'maintain_ration' => true,
        'width' => 150,
        'height' => 100
        );
    $this->load->library('image_lib', $config);
    $this->image_lib->resize();
}
function get_images(){
    $files = scandir($this->gallery_path);
    $files = array_diff($files, array('.','..','thumbs'));

    $images = array();

    foreach ($files as $files) {
        $images []= array(
            'url'=> $this->gallery_path_url . $files,
            'thumb_url' => $this->gallery_path_url . 'thumbs/' . $files
            );
    }
    return $images;
}
}

您能帮忙吗?

推荐答案

  'new_image' => $this->gallery_path . '/thumbs',

设置目标映像名称/路径。创建映像副本时,将使用此首选项。 路径必须是相对或绝对的服务器路径,而不是网址。

Sets the destination image name/path. You'll use this preference when creating an image copy. The path must be a relative or absolute server path, not a URL.

您将new_image设置为文件夹,而不是文件名。使它像$ this-> gallery_path。 '/thumbs/my_new_file.ext'

you set new_image as folder, not filename. make it like $this->gallery_path . '/thumbs/my_new_file.ext'

这篇关于Codeigniter权限被拒绝的图像上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆