Codeigniter文件上传内部服务器错误 [英] Codeigniter File Upload Internal Server Error

查看:52
本文介绍了Codeigniter文件上传内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试上传文件时,出现HTTP 500错误。如果有人可以指出我正确的方向。下面有三个文件,Upload.php,upload_success.php和upload_form.php。我已经正确设置了自动加载,配置,数据库文件。

When I try to upload a file, I get a HTTP 500 Error. If someone could point me in the right direction. There are three files below, Upload.php, upload_success.php, and upload_form.php. I have properly setup the autoload, config, database files.

        <?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>


推荐答案

在共享主机上,您很可能需要其他方式相对路径,而不是在localhost环境中:

on a shared hosting, you most likely need a different relative path than on a localhost environment:

您可以在localhost环境中使用

you can use on a localhost environment

$config['upload_path']   = './uploads/'; 

但是在共享主机上,您需要提供更具体的信息,例如

but on a shared hosting, you'll need to supply more specific, something like

$config['upload_path']   = '/home/yourserver/public_html/uploads/'; 

您可以在左侧列的帐户cPanel主页中找到此内容,或致电您的提供商帮助台以获取更多信息正确路径上的信息

you can find this in your accounts cPanel main page on the left column or call your providers helpdesk for more info on the correct path

这篇关于Codeigniter文件上传内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆