代码之家  ›  专栏  ›  技术社区  ›  Drew Rich

我不能用codeigner上传MP3文件

  •  0
  • Drew Rich  · 技术社区  · 16 年前

    有很多建议的修复方法,但都不适合我。我尝试过制作上传类(使用以下方法: Method1 Method2 ) 当我尝试上传MP3时,会收到以下错误消息

    不允许您尝试上载的文件类型

    下面是我的模型和表单代码(我有一个非常瘦的控制器)。如果有人能帮我解决这个问题,我将永远感激。

    模型

    function do_upload()
    {
    
            $soundfig['upload_path'] = './uploads/nav';
            $soundfig['allowed_types'] = 'mp3';
    
            $this->load->library('upload', $soundfig);
    
            if ( ! $this->upload->do_upload())
            {
                $error = array('error' => $this->upload->display_errors());
    
                return $error;
            }   
            else
            {
    
                /* $data = $this->upload->data('userfile'); */
                $sound = $this->upload->data();
                /* $full_path = 'uploads/nav/' . $data['file_name']; */
                $sound_path = 'uploads/nav/' . $sound['file_name'];
    
                if($this->input->post('active') == '1'){
                    $active = '1';
                }else{
                    $active = '0';
                }
    
                $spam = array(
                    /* 'image_url' => $full_path, */
                    'sound' => $sound_path,
                    'active' => $active,
                    'url' => $this->input->post('url')
                );
    
                $id = $this->input->post('id');
    
                $this->db->where('id', $id);
                $this->db->update('NavItemData', $spam);
    
                return true;
    
        }
    }
    

    视图形式

    <?php echo form_open_multipart('upload/do_upload');?>
    <?php if(isset($buttons)) : foreach($buttons as $row) : ?>
    <h2><?php echo $row->name; ?></h2>
    <!-- <input type="file" name="userfile" size="20" /><br /> -->
    <input type="file" name="userfile" size="20" />
    <input type="hidden" name="oldfile" value="<?php echo $row->image_url; ?>" />
    <input type="hidden" name="id" value="<?php echo $row->id; ?>" />
    
    <br /><br />
    <label>Url: </label><input type="text" name="url" value="<?php echo $row->url; ?>" /><br />
    <input type="checkbox" name="active" value="1" <?php if($row->active == '1') { echo 'checked'; } ?> /><br /><br />
    <input type="submit" value="submit" />
    
    </form>
    
    <?php endforeach; ?>
    <?php endif; ?>
    
    1 回复  |  直到 10 年前
        1
  •  4
  •   Bella    16 年前

    是的,我在将文档/图像类型上载到CodeIgniter的文件上载类时遇到了类似的问题;我的解决方法是为我遇到类似问题的每种类型添加“application/octet-stream”MIME类型:

    在application/config/mimes.php中

    'jpeg'  =>  array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
    'jpg'   =>  array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
    'jpe'   =>  array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
    'png'   =>  array('image/png',  'image/x-png', 'application/octet-stream'), 
    
    推荐文章