當我嘗試上載文件時,出現HTTP 500錯誤。如果有人能指引我正確的方向。下面有三個文件,Upload.php,upload_success.php和upload_form.php。我已經正確設置了自動加載,配置,數據庫文件。Codeigniter文件上傳內部服務器錯誤
<?php
class Upload extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->database();
}
public function index() {
$this->load->view('upload_form', array('error' => ' '));
}
public function do_upload() {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = '*';
$config['max_size'] = 100;
$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_form', $error);
}
else {
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
}
?>
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<h3>Your file was successfully uploaded!</h3>
<ul>
<?phpforeach ($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?phpendforeach; ?>
</ul>
<p><?php echo anchor('upload', 'Upload Another File!'); ?></p>
</body>
</html>
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo $error;?>
<?php echo form_open_multipart('upload/do_upload');?>
<form action = "" method = "">
<input type = "file" name = "userfile" size = "20" />
<br /><br />
<input type = "submit" value = "upload" />
</form>
</body>
</html>
你使用本地主機服務器或生產服務器(如共享主機服務器)? – Vickel
也許是一個權限問題? – Pipe
可能是你的htaccess文件和文件夾權限0777上傳文件夾也確保你已經設置你的配置基地址不要留在config.php空白 – user4419336