我的問題是,我有一個在本地主機上而不是生產服務器上工作的代碼。我想通過表單上傳文件。在localhost中一切正常,但在生產服務器上,我得到'你沒有選擇要上傳的文件'錯誤。無法上傳與笨do_upload文件
視圖部分
<?php echo form_open_multipart('Ajax/do_upload');?>
<input type="file" name="file">
<input type="submit" name="submit" value="upload image" />
<?php echo form_close();?>
控制器部分(控制器的Ajax,功能do_upload)
public function do_upload(){
$config['upload_path'] = './assets/images/usr_uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = 5000;
$config['max_width'] = 2048;
$config['max_height'] = 2048;
$config['overwrite'] = true;
$this->load->library('upload', $config);
$this->upload->initialize($config);
$filename = $_FILES['file']['name'];
if (!$this->upload->do_upload("file")){
//$data['error'] = "An error occurred while uploading the image.";
$error = array('error' => $this->upload->display_errors());
//echo $filename;
print_r($_FILES);
$this->load->view('template/head.php');
$this->load->view('profileview.php', $error);
$this->load->view('template/footer.php');
} else {
$filename = $_FILES['file']['name'];
$data['up_ok'] = $filename;
print_r($_FILES);
$this->savefn($filename);
$this->updatesesssion();
$this->load->view('template/head.php');
$this->load->view('profileview.php', $data);
$this->load->view('template/footer.php');
}
}
.htaccess文件
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
所以問題是,當生產服務器上,它不會從窗體中獲取任何文件。在本地主機上它的工作原理應該如此。我找不到這個問題的原因,並且我嘗試了幾乎所有我找到的東西。我也曾嘗試用默認userfile的,這再次工作本地主機,但不能在服務器上,我已經設置文件夾的權限爲777
是'$配置[「BASE_URL」]'值設置呢? '.htaccess'呢? – Tpojka
base_url很好。 htaccess文件:RewriteEngine on RewriteCond%{REQUEST_FILENAME}!-f RewriteCond%{REQUEST_FILENAME}!-d RewriteRule ^(。*)$ index.php?/ $ 1 [L] –
請複製該代碼並使用代碼編輯您的問題標籤是可讀的。 – Tpojka