dphj737575 2015-11-18 13:55
浏览 39
已采纳

使用codeigniter(3.1)上传文件失败


I'm having a problem with uploading files with Codeigniter framework. Currently is working like this:
If i don't select any file in HTML form, then variables like $title = $this->input->post('title'); gets value,
but when i select file in html form, then all variables are null and i get message file is not selected.

My .htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

My autoload.php file

$autoload['helper'] = array('url', 'file', 'form');
$autoload['libraries'] = array('database', 'session', 'email', 'form_validation');
$autoload['model'] = array('model_services' => 'ms', 'Model_categories' => 'mc');

My controller which is rendering view:

 public function add_catalog() {
        if ($this->is_admin() == TRUE) {
            $data['cat'] = $this->mc->get();
            $this->load->view('admin_view_map/admin_header');
            $this->load->view('admin_view_map/admin_add_catalog', $data);
            $this->load->view('admin_view_map/admin_footer');
        } else {
            $this->index();
        }
    }

HTML:

<?php echo form_open_multipart('admin321/insert_catalog'); ?>
    *title: <input type="text" name="title" />
    sub_title: <input type="text" name="sub_title" />
    Facebook url: <input type="text" name="facebookUrl" />
    Twitter url: <input type="text" name="twitterUrl" />
    Google +: <input type="text" name="googlePlus" />
    description: <input type="text" name="description" />
    pdf: </span> <input type="file" name="pdf" />
    categories:
    <select name="categories" >
        <?php foreach ($cat as $r) {
                echo '<option value=' . $r->id_category . ' >' . $r->category . '</option>';
        } ?>
    </select>
    <input type="submit" value="Add" class="submit">
<?php echo form_close(); ?>

PHP:

public function insert_catalog(){
    $title = $this->input->post('title');
    $sub_title = $this->input->post('sub_title');
    $facebookUrl = $this->input->post('facebookUrl');
    $twitterUrl = $this->input->post('twitterUrl');
    $googlePlus = $this->input->post('googlePlus');
    $description = $this->input->post('description');
    $category = $this->input->post('categories');
    var_dump($title,$sub_title,$facebookUrl,$twitterUrl,$googlePlus,$description,$category);

    $config['upload_path'] = './assets/pdf/';
    $config['allowed_types'] = 'pdf';
    $this->load->library('upload', $config);

    if (!$this->upload->do_upload('pdf')){
        var_dump($this->upload->display_errors());
        die();
    }else{
        $pdf = array('upload_data' => $this->upload->data());
        var_dump($pdf);
        die();
    }

}

This make result like this:

null
null
null
null
null
null
null
string '<p>You did not select a file to upload.</p>' (length=43)

I'm using WAMP server and this are my php.ini configuration

; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
upload_tmp_dir = "e:/wamp/tmp"

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 64M
  • 写回答

3条回答 默认 最新

  • donglei1616 2015-11-19 13:38
    关注

    Check your php's installation settings in php.ini regarding upload configuration

    upload_max_filesize  = 10M
    post_max_size  = 10M
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?