我已经尝试了所有选项并检查了有关此案例的每个问题,所以现在我正在打开你们。我上传pdf文件的上传路径有问题。
我的观点:
<?php echo form_open_multipart('admin321/insert_catalog'); ?>
*title: <input type="text" name="title" />
sub_title: <input type="text" name="sub_title" />
Facebook url: <input type="text" name="facebookUrl" />
Twitter url: <input type="text" name="twitterUrl" />
Google +: <input type="text" name="googlePlus" />
description: <input type="text" name="description" />
pdf: </span> <input type="file" name="pdf" />
categories:
//Here i fetch some categories object and parse them in select options
<select name="categories" >
<?php foreach ($cat as $r) {
echo '<option value=' . $r->id_category . ' >' . $r->category . '</option>';
} ?>
</select>
<input type="submit" value="Add" class="submit">
<?php echo form_close(); ?>
我在控制器中的insert_catalog函数
public function insert_catalog(){
$title = $this->input->post('title');
$sub_title = $this->input->post('sub_title');
$facebookUrl = $this->input->post('facebookUrl');
$twitterUrl = $this->input->post('twitterUrl');
$googlePlus = $this->input->post('googlePlus');
$description = $this->input->post('description');
$category = $this->input->post('categories');
$config['upload_path'] = '/assets/pdf/';
$config['allowed_types'] = 'pdf';
$this->load->library('upload', $config);
$this->upload->set_xss_clean(TRUE);
if (!$this->upload->do_upload()){
var_dump($this->upload->display_errors());
die();
}else{
$pdf = array('upload_data' => $this->upload->data());
var_dump($title,$sub_title,$facebookUrl,$twitterUrl,$googlePlus,$description,$category);
var_dump($pdf);
die();
}
}
我的文件夹结构是基本的codeingiter 3.0.1,在我的网页的根目录中添加了资产文件夹
- application
- assets
-- pdf
-- css
-- js
-- ...
- system
到目前为止,我已尝试过:
$config['upload_path'] = './assets/pdf/';
$config['upload_path'] = '/assets/pdf';
$config['upload_path'] = 'assets/pdf';
$config['upload_path'] = 'assets/pdf/';
$config['upload_path'] = 'e:/wamp/www/mypage';
$config['upload_path'] = 'e:\wamp\www\mypage';
$config['upload_path'] = FCPATH."/asset/pdf";
$config['upload_path'] = "../asset/pdf";
$config['upload_path'] = "../../asset/pdf";
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT']."/assets/pdf";
$config['upload_path'] = 'E:\\wamp\\www\\hot/asset/pdf';
$config['upload_path'] = FCPATH . 'assets/pdf/';
基本上我已经尝试了所有组合,没有任何工作,所以我相信问题必须在其他地方。
我的.htaacess文件
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
我也有虚拟主机
<VirtualHost *:80>
ServerAdmin info@hot.si
DocumentRoot "E:/wamp/www/mypage"
ServerName www.mypage.si
ServerAlias hot.si *.mypage.si
ErrorLog "E:/wamp/www/mypage/application/logs/mypage.log"
CustomLog "E:/wamp/www/mypage/application/logs/mypage.log" common
<Directory E:/wamp/www/mypage>
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
我在Windows 10上使用WAMP服务器。
我希望有人可以指出我正确的方向。如果您需要任何其他信息,请告诉我
提前谢谢!
答案 0 :(得分:3)
您应该指定表单字段的名称&#39; file&#39;在&#39; do_upload&#39;否则codeigniter将采用默认值&#39; userfile&#39;。
在您的情况下,将$this->upload->do_upload()
更改为$this->upload->do_upload('pdf')