1
我有問題。我在Xampp Lite上使用CodeIgniter並且上載表單不起作用,它返回codeigniter上傳不起作用
您沒有選擇要上載的文件。
我聲明表單multipart,輸入的名稱是userfile,我設置所有上傳相關的變量,但它不起作用。
這裏的源代碼的一部分:
控制器
public function send($id,$doupload=false) {
$this->load->helper(array('form','url', 'html'));
$config =
array(
'upload_path' => dirname($_SERVER["SCRIPT_FILENAME"])."/files/",
'upload_url' => base_url()."files/",
'allowed_types' => "cpp",
'overwrite' => TRUE,
'max_size' => "1000KB",
);
$this->load->library('upload',$config); $data=array( 'page_title'=>lang('send_source'),
'form_sursa'=>array(
'name' => 'userfile',
'id' => 'sursa',
'size' => 20, ),
'id' => $id );
if ($doupload===false) {
$this->template->build('problems/send',$data); } else { if
(! $this->upload->do_upload()) {
echo ($data['upload_error'] = $this->upload->display_errors());
$this->template->build('problems/send',$data); } else {
$data['upload_data'] = $this->upload->data();
$this->template->build('problems/send',$data); } } }
模板的形式部分:
<?php echo form_open_multipart(site_url('probleme/trimite').$id./trimite',array('class'=>'form-horizontal'));
?>
<fieldset>
<div class="control-group">
<?php echo form_label(lang('sursa'), 'sursa', array('class' => 'control-label')); ?>
<input type="hidden" name="MAX_FILE_SIZE" value="99999999" />
<div class="controls"><?php echo form_upload($form_sursa); ?
><br
/>*<i><?php echo lang('sursa_upload_tip1'); ?></i></div>
</div>
<div class="span7 offset2">
<div class="span2" style="text-align: center;">
<?php echo form_submit(array('name' => 'submit', 'value' =>
lang('upload_source'), 'class' => 'btn')); ?>
</div>
<div class="clearfix hspace"></div>
</div>
</fieldset>
htaccess的
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
# rewrite `pub/` requests
# IE: [app_path]/themes/default/css/ maps to [app_path]/pub/themes/default/css/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?:themes|upload)\b.* pub/$0 [L]
# this adds trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [R=301,L]
# Secure directories
RewriteRule ^(app|core) index.php [R=404,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|pub|favicon\.ico|robots\.txt|humans\.txt\|sitemap\.gz|sitemap\.xml)
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
<IfModule !mod_rewrite.c>
# Prevent directory listings
Options -Indexes
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
#
# -> Remember to add the subdirectory if necessary.
#
ErrorDocument 404 /index.php
</IfModule>
你甩了$ _FILES,看它是否有文件? – user20232359723568423357842364
'VAR_DUMP()'你的'$ _FILES'數組確保文件實際上被髮送到你的控制器。 –
哪個版本的CodeIgniter? CI 2.1.1修復了由於不正確的MIME類型檢測而導致此症狀的錯誤。 http://ellislab.com/codeigniter/user-guide/changelog.html – Wolf