http://www.codeigniter.com/user_guide/libraries/file_uploading.html?highlight=file%20upload
但我总是遇到这个错误 localhost http 500 error
请有人帮助我。
这是我的控制器
class Upload extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
public function index()
{
$this->load->view('upload_view', array('error' => ' ' ));
}
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1000;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_view', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}}
这是我的观点upload_view.php
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo $error;?>
<?php echo form_open_multipart('upload/do_upload');?>
<input type="file" name="userfile" size="20" />
<input type="submit" value="upload" />
<?php form_close(); ?>
</body>
</html>
和upload_success.php
<html>
<head>
<title> Image Upload </title>
</head>
<body>
<div id="container">
<dl>
<dt>
File Name:
</dt>
<dd>
<?php echo $uploadInfo['file_name'];?>
</dd>
<dt>
File Size:
</dt>
<dd>
<?php echo $uploadInfo['file_size'];?>
</dd>
<dt>
File Extension:
</dt>
<dd>
<?php echo $uploadInfo['file_ext'];?>
</dd>
<br />
<p>The Image:</p>
<img alt="uploaded image" src="<?=base_url(). 'uploads/' . $uploadInfo['file_name'];?>">
</dl>
</div>
</body>
</html>
答案 0 :(得分:0)
将文件夹文件权限更改为chmod -R 777 foldername