【问题标题】:Url redirection problems uploading a file in Codeigniter 2.0.2在 Codeigniter 2.0.2 中上传文件的 URL 重定向问题
【发布时间】: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


【解决方案1】:

基于问题的cmets:

$config['base_url'] = 'http://localhost/codeigniter/';

【讨论】:

    【解决方案2】:
    $config['base_url'] = 'http://localhost/set root folder name here/';
    

    并使用这个变量&lt;?php echo

    【讨论】:

      【解决方案3】:

      更改上传对象的变量名,而不是 $config例如:

      $this->**config2** =  array(
                                'upload_path'     => "/root/user_name/public_html/*/files",
                                'upload_url'      => "/root/user_name/public_html/*/files",
                                'allowed_types'   => "pdf|doc",
                                'overwrite'       => TRUE
                            );
      $this->load->library('upload', $this->config2);
                      if(!$this->upload->do_upload())
                      {
                           $error = array('error' => $this->upload->display_errors());
                         print_r($error);
                      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-11-12
        • 2016-07-02
        • 2015-04-15
        • 2012-01-09
        • 2021-08-27
        • 2011-09-25
        • 2018-01-14
        • 2015-11-23
        相关资源
        最近更新 更多