0

我创建了与CI 用户指南完全相同的副本,我什至更改了
$this->upload->do_upload("name_of_file_input"); 我都尝试了

./data/
./application/data/

作为我要上传的文件夹,CHMOD 0777,仍然无法上传。
我启动了 FF 和 FireBug 来查看我从本地主机发送/获取的标头,我认为问题可能出在 .htaccess 文件中,但不太确定……
我在子文件夹上工作,localhost/something/ (or http://192.168.0.101/sms/)
我的 routes.php 应该没问题,没有 404 或除了上传脚本之外的任何其他问题

另外奇怪的是我必须制作这样的表格

<?=form_open_multipart("/sms/upload/do_upload")?>

这创造了这个

<form action="http://localhost/sms/sms/upload/do_upload" method="post" accept-charset="utf-8" enctype="multipart/form-data">

注意double sms/sms/这显然是错误的,但是我的 htaccess 它正确重定向,如您在此处看到的

HTTP/1.1 301 Moved Permanently
Date: Tue, 28 Aug 2012 01:49:47 GMT
Server: Apache/2.4.2 (Win32) OpenSSL/1.0.1c PHP/5.4.4
Location: http://192.168.0.101/sms/upload
Content-Length: 337
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1

如果我创建这样的表格

<?=form_open_multipart("/upload/do_upload")?>

它当然会很好地给我一个错误

HTTP/1.1 301 Moved Permanently
Date: Tue, 28 Aug 2012 01:52:43 GMT
Server: Apache/2.4.2 (Win32) OpenSSL/1.0.1c PHP/5.4.4
Location: http://192.168.0.101/upload/do_upload

显然我的本地主机上不存在http://192.168.0.101/upload我的整个安装在子文件夹/sms/

我的 .htaccess下

<IfModule mod_rewrite.c>
# mod_rewrite rules
RewriteEngine on

# The RewriteBase of the system (if you are using this sytem in a sub-folder).
 RewriteBase /sms/

# This will make the site only accessible without the "www."
# (which will keep the subdomain-sensive config file happy)
# If you want the site to be accessed WITH the "www."
# comment-out the following two lines.
 RewriteCond %{HTTP_HOST} !^192.168.0.101$ [NC]
 RewriteRule ^(.*)$ http://192.168.0.101/$1 [L,R=301]

# If a controler can't be found - then issue a 404 error from PHP
# Error messages (via the "error" plugin)
# ErrorDocument 403 /index.php/403/
# ErrorDocument 404 /index.php/404/
# ErrorDocument 500 /index.php/500/

# Deny any people (or bots) from the following sites: (to stop spam comments)
# RewriteCond %{HTTP_REFERER} nienschanz\.ru [NC,OR]
# RewriteCond %{HTTP_REFERER} porn\.com
# RewriteRule .* - [F]
# Note: if you are having trouble from a certain URL just
# add it above to forbide all visitors from that site.

# You can also uncomment this if you know the IP:
# Deny from 192.168.1.1

# If the file is NOT the index.php file
RewriteCond %{REQUEST_FILENAME} !index.php
# Hide all PHP files so none can be accessed by HTTP
RewriteRule (.*)\.php$ index.php/$1

# If the file/dir is NOT real go to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]

</IfModule>

# If Mod_ewrite is NOT installed go to index.php
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>

#<ifModule mod_expires.c>
#  <filesmatch "\.(ico|flv|jpg|jpeg|png|gif|js|css|swf)$">
#       ExpiresActive on
#       ExpiresDefault "access plus 1 year"
#   </filesmatch>
#</ifModule>

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/xhtml text/html text/plain text/xml
text/javascript application/x-javascript text/css
</IfModule>
FileTag none

新信息:

似乎在点击“上传”按钮后,它被重定向到“某处”(带有“附加”数据),并从“某处”重定向到我的实际上传脚本,该脚本完成所有工作(没有“附加”数据)因此我认为这是.htaccess的问题。CI 抛出此错误

您没有选择要上传的文件。

<?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'] = './data/';
    //$config['allowed_types'] = 'gif|jpg|png';
    //$config['max_size']   = '100';
    //$config['max_width']  = '1024';
    //$config['max_height']  = '768';
    //$config['file_name'] = $_FILES['userfile']['name'];
    $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);
    }
   }
  }
 ?>

这是我在上面链接的 CI 指南的副本

4

2 回答 2

1

最后 :) 问题出在相对/绝对路径或实际上是我的 CodeIgniter 设置中,我的 config.php 中有这一行

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

这一切都很好,但是在我的 .htaccess 文件中没有提到 localhost (有IP)。

通过在配置文件和 .htaccess 文件中放置相同的“路径”来解决整个问题

于 2012-08-28T10:01:53.393 回答
0

为什么不使用相对链接?(删除初始斜线'/')

您为上传文件创建了目标文件夹并更改了权限?

尝试删除 RewriteBase /sms/

如果您希望 url 相同,请更改 apache 配置文件中的 documentRoot

希望这可以帮到你。如果没有,请从您的代码中添加更多内容。

于 2012-08-28T03:59:35.070 回答