【发布时间】:2013-08-16 15:13:16
【问题描述】:
我正在尝试使用 Codeigniter 上传图像,遵循 CI 用户指南 - 但由于 url 重定向而出现错误。
这是我的看法upload_form.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" />
<br /><br />
<input type="submit" value="upload" />
</form>
</body>
</html>
查看 2upload_success.php:
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<h3>Your file was successfully uploaded!</h3>
<ul>
<?php foreach ($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>
<p><?php echo anchor('upload', 'Upload Another File!'); ?></p>
</body>
</html>
控制器upload.php:
<?php
class Upload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
function index()
{
$this->load->view('upload_form', array('error' => ' ' ));
}
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$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);
}
}
}
?>
我在“project_name”文件夹下添加了文件夹“uploads”。
我正在使用这个 url 上传表单:
localhost/project_name/index.php/upload/
提交后我收到“找不到页面”错误,并且 url 变为:
http://localhost/project_name/index.php/upload/localhost/project_name/index.php/upload/do_upload
【问题讨论】:
-
config/config.php 下的 $config['base_url'] 的值是多少?因为问题是 url 应该是 http://localhost 而不是 localhost。
-
感谢您的回复。基本网址是
-
基本 url 是:$config['base_url'] = 'http:localhost/codeigniter'; codeigniter 是项目名称。
-
is // 部分被剪掉了,因为它在 cmets 中,还是丢失了? $config['base_url'] = 'localhost/codeigniter';
-
非常感谢你......这是一个愚蠢的错误......
标签: php codeigniter