代码点火器+wamp”;上传路径似乎不是有效的“;


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();
    }
}

我的文件夹结构是基本的编码,在我的网页的根目录中添加了资产文件夹

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

基本上,我尝试过每一种组合,但都不起作用,所以我相信问题一定出在其他地方。

我的.htacess文件

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>

我在Windows10上使用WAMP服务器。

我希望有人能给我指明正确的方向。如果你需要任何额外的信息,请让我知道

提前谢谢!

您应该在"do_upload"中指定表单字段"file"的名称,否则代码点火器将采用默认值"userfile"。

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