【问题标题】:file upload not upload in folder codeigniter文件上传不在文件夹codeigniter中上传
【发布时间】:2016-03-11 18:03:46
【问题描述】:

我有问题,我的 orig_name 文件上传成功上传到数据库但文件没有上传到我的文件夹中..

这是我的控制器代码

public function insert(){
        $this->model->register();
        $this->run_upload();
        redirect('Controling/daftar');
    }
    public function run_upload(){
        $config['upload_path'] = './upload/';
        $config['allowed_types'] = 'gif|jpg|png|pdf';
        $config['max_size'] = '100000';
        $config['max_width'] = '3024';
        $config['max_heigth'] = '2024';

        $this->load->library('upload', $config);

            $data = array('upload_data' => $this->upload->data());
            $datafoto=$this->upload->data();
            $nm_file = time().$datafoto['orig_name'];
            $this->load->model('model');
            $this->model->update_file($nm_file);
            copy('upload/'.$datafoto['orig_name'], 'upload/'.$nm_file);
    }

这是我的视图代码

<?php echo form_open_multipart('Controling/insert', 'form="form"')?>
        <h2 class="">Register</h2>
        <label>Nim</label><input type="text" name="nim" class="form-control"><br />
        <label>Username</label><input type="text" name="username" class="form-control"><br />
        <label>Password</label><input type="password" name="password" class="form-control"><br />
        <label>Masukkan File</label>
        <input type="file" name="userfile" size="20" class="form-control"><br />
        <input class="btn btn-primary" type="submit" name="register" value="Daftar">
    <?php echo form_close(); ?>

【问题讨论】:

  • $config['upload_path'] = './upload/';改成$config['upload_path'] = '../upload/';看看。
  • 它不工作娜娜
  • 用于将文件移动到文件夹。你在用这条线copy('upload/'.$datafoto['orig_name'], 'upload/'.$nm_file);吗?
  • 是的,我认为这行得通,为什么?
  • 试试这个 $config['upload_path'] = str_replace("\\","/",FCPATH).'upload/';并设置777上传文件夹

标签: php file codeigniter file-upload


【解决方案1】:

在 config/mimes.php 中添加您要上传的缺失文件类型,如下所示。

'mpeg'  =>  array('video/mpeg', 'video/quicktime'),
'mpg'   =>  array('video/mpeg', 'video/quicktime'),
'mp4'   =>  array('video/mp4', 'video/quicktime'),
'mpe'   =>  array('video/mpeg', 'video/quicktime'),
'qt'    =>  'video/quicktime',
'mov'   =>  array('video/quicktime', 'video/mp4'),
'avi'   =>  array('video/avi', 'video/x-msvideo'),

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-26
    • 2014-01-06
    • 2017-05-17
    • 1970-01-01
    • 1970-01-01
    • 2012-04-22
    • 2013-07-27
    相关资源
    最近更新 更多