代码点火器 + wamp "The upload path does not appear to be valid"

Codeigniter + wamp "The upload path does not appear to be valid"

我已经尝试了所有选项并检查了与此案例有关的每个问题,所以现在我要找你们了。我上传 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,在我的网页根目录中添加了 assets 文件夹

- 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/';

基本上我已经尝试了每一种组合,但没有任何效果,所以我相信问题一定出在其他地方。

我的 .htaac​​ess 文件

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [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 服务器

我希望有人能给我指出正确的方向。如果您需要任何其他信息,请告诉我

提前致谢!

您应该在 'do_upload' 中指定表单字段的名称 'file' 否则 codeigniter 将采用默认值 'userfile'.

在您的情况下,将 $this->upload->do_upload() 更改为 $this->upload->do_upload('pdf')