【发布时间】:2016-12-14 08:25:38
【问题描述】:
当我尝试上传文件时,我收到 HTTP 500 错误。如果有人能指出我正确的方向。下面共有三个文件,Upload.php、upload_success.php 和upload_form.php。我已经正确设置了自动加载、配置、数据库文件。
<?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>
【问题讨论】:
-
您使用的是本地主机服务器还是生产服务器(如共享托管服务器)?
-
可能是权限问题?
-
可能是您的 htaccess 文件和文件夹权限 0777 用于上传文件夹,还请确保您已设置配置基本 url 不要在 config.php 中将其留空
-
抱歉没有看到这些cmets。我正在使用共享托管服务器(godaddy)。在文件管理器中,我授予了位于根目录的“上传”文件夹的权限,并且我已经设置了我的基本 URL。谁能指导我访问我应该使用的 .htaccess 文件?
-
你修复错误了吗?
标签: php codeigniter