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条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵