2012-02-24 46 views
0

这里是上传功能:笨照片上传在非允许的类型没有错误警告文件

$config['upload_path'] = './photos/'; 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $config['max_size'] = 1024 * 2; 
    $config['encrypt_name'] = true; 

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

    if (!$this->upload->do_upload("photo_data")) 
    { 
     $this->error = true; 
     $this->response = $this->upload->display_errors('', ''); 
    } 
    else 
    { 
     $this->upload->data(); 
     $this->response = "Photo successfully changed."; 
    } 

    $array = array(
     'error' => $this->error, 
     'response' => $this->response 
    ); 

    return $array; 

不过,为了测试它不容许的文件类型,除了一个,我让我改名的视频,以.JPG并试图把它上传...

它没有继续进行,但它没有也发送一个错误信息......我在upload classreturns false somwhere想......任何想法如何确保它发送一条消息给用户至上?

回答

0

如何在视图中打印错误?在上传类返回false某处的方法是,你已经签了假的人,即$this->upload->do_upload()

你应该通过这些错误的观点,如果你希望自己的网站显示它们:

这是假设的代码你贴是从控制器:

$array = array(
     'error' => $this->error, 
     'response' => $this->response 
    ); 

$this->load->view('upload_view',$array); 
//instead of returning, as "return" in a controller makes little sense. If you're inside a model, then, get the returned value in a controller and pass it to a view. 

在你的 “upload_view.php” 查看文件:

<div class="<?php $error? 'error' : 'success';?>"><?php echo $response;?></div> 
+0

这就是我怎么打印错误:<?PHP的,如果(isset($ U pload_data [“error”])):?>

<?php endif; ?> 事情是,它不进入任何有条件的,如果文件是从一个视频重新命名.jpg在任何情况下.... – fxuser 2012-02-24 20:37:24

+0

你在哪里设置$ upload_data变量?我没有在你发布的代码中看到它...... Sidenote(和不相关的):你传递$ config两次,不管是在加载库还是使用初始化时传递它作为第二个参数,而不是 – 2012-02-24 20:46:56

+0

它在用户类数组被发送到视图,所以我回应错误,如果我有上传后完成任何错误 – fxuser 2012-02-24 20:54:03