【问题标题】:When Try to upload image localhost http error 500 codeigniter当尝试上传图像 localhost http 错误 500 codeigniter
【发布时间】:2017-04-19 10:11:29
【问题描述】:

谁能帮助我? 当我尝试使用 codeigniter 文件上传类上传图像时,就像在

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>

【问题讨论】:

    标签: codeigniter file-upload


    【解决方案1】:

    将您的文件夹文件权限更改为 chmod -R 777 文件夹名称

    【讨论】:

    • 已经按照你说的那样做了,但仍然遇到错误页面 [::1] 无法正常工作
    • 你用的是哪个版本??
    • 库有问题..下载旧版本 2.2.6 并将所有旧库复制到您的系统->库..再一次。
    • 替换libraires后使用此代码: //上传文件夹应该在应用程序文件夹中 $config['upload_path'] = APPPATH.'uploads/upload/'; $config['allowed_types'] = '*'; $this->load->library('upload', $config); $this->上传->初始化($config); $upload=$this->upload->do_upload('fileToUpload');
    • 感谢@gulshan 帮助我哈哈.. 这是我的愚蠢,实际上它运行良好,当我更新我的 xampp 时,>.
    猜你喜欢
    • 1970-01-01
    • 2015-10-08
    • 2012-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-03
    • 2021-03-13
    • 1970-01-01
    相关资源
    最近更新 更多