CI User Guideとまったく同じコピーを作成しましたが、変更も加えまし$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/)
ています。アップロードスクリプト以外の他の問題
また、奇妙なことは、このようなフォームを作成する必要があることです
<?=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">
明らかに間違っているダブル sms/sms/に注意してください。
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/
my .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ガイドのコピーです