我有个问题。我在 Xampp Lite 上使用 CodeIgniter,上传表单不起作用,它返回
您没有选择要上传的文件。
我声明了表单多部分,输入的名称是用户文件,我设置了所有与上传相关的变量,但它不起作用。
这是源代码的一部分:
控制器
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>