2012-08-03 95 views
0

我在上传CodeIgniter中的文件时遇到问题。这是我的自动加载:$autoload['helper'] = array('url', 'form', 'file');Codeigniter尝试上传文件时什么都不显示

我已经呼应了realpath(APPPATH . '../images');,它是正确的位置。当我点击提交时,没有任何反应,也没有显示错误;它只是重新加载视图。

型号:

<?php 
class Gallery_model extends CI_Model{ 

var $gallery_path; 

function __construct() 
{ 
    parent::__construct(); 

    $this->gallery_path = realpath(APPPATH . '../images'); 

} 

function do_upload() 
{ 

    //handle userfile 
    $config = array(
     'allowed_types' => 'jpg|jpeg|gif|png', 
     'upload_path' => $this->gallery_path 

    ); 


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

} 


} 

?> 

控制器:

<?php 
class Gallery extends CI_Controller 
{ 
function index() 
{ 
    $this->load->model('Gallery_model'); 
    if($this->input->post('upload')) 
    { 
     //handle upload 
     $this->Gallery_model->do_upload(); 
    } 

    $this->load->view('gallery'); 
} 


} 


?> 

查看:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 

<title>Gallery</title> 

</head> 

<body> 
<div id="gallery"> 

</div> 

<div id="upload"> 

<?php 

echo form_open_multipart('gallery'); 
echo form_upload('userfile'); 
echo form_submit('upload', 'Upload'); 
echo form_close(); 
?> 

</div> 

</body> 
</html> 

问题是什么?

回答

0

如果你有$this->upload->do_upload(),替换成:

if(!$this->upload->do_upload()) 
{ 
    die($this->upload->display_errors()); 
} 

这样就可以找出错误是什么。

+0

感谢,似乎是不可写的 – user1250526 2012-08-03 18:07:56

1

确保“到的路径上载应放在该文件夹必须是可写的文件夹和路径可以是绝对或相对的。”

我刚才复制的代码,图像可以上传。

+0

所以它适合你?这个地方是正确的我通过回弹来检查它,我非常肯定它是可写的,但我会看看,是否需要777? 什么是绝对或相对路径? – user1250526 2012-08-03 18:03:52

+0

文件夹需要是777.我在我的代码中创建路径'upload_path'=>'public/uploads /',其中与index.php相关 – Janblus 2012-08-03 18:25:34

+0

再次感谢您的帮助,您是对的,但我无法找到,除非我有顶部的球员代码,似乎迫使CI显示错误,但非常感谢你! – user1250526 2012-08-03 18:37:30

相关问题