简体   繁体   English

使用codeigniter上传PDF文件

[英]uploading PDF files with codeigniter

Hi I'm very new to stackoverflow and codeigniter so I apologize if I'm breaking any rules or etiquette with this question (I did a search of the related questions and didn't see anything that related directly to my question). 嗨,我对stackoverflow和codeigniter还是很陌生,所以如果我违反任何规则或礼节对此表示歉意(我搜索了相关问题,但没有发现与我的问题直接相关的任何内容)。

I'm trying to upload a PDF file, and I'm using the following code (codeigniter version 1.7.2): 我正在尝试上传PDF文件,并且正在使用以下代码(codeigniter版本1.7.2):

    function test(){
        $this->load->library('upload');   
        $config['upload_path'] = './assets/certificates/';
        $config['allowed_types'] = 'pdf';
        $config['max_size']    = '1000000';
        $config['file_name'] = "test";

        $this->upload->initialize($config);
        $certificateflag = $this->upload->do_upload("certificate");       
        if ($this->upload->do_upload("certificate"))
            error_reporting(E_ALL);
        else{
            echo "<pre>"; Print_r($this->upload->data()); echo "</pre>";
        }
}

I don't get any errors, and it appears that the file gets uploaded, but it doesn't appear in the directory, and I can't find it anywhere on the server. 我没有任何错误,文件似乎已上传,但未出现在目录中,并且在服务器上的任何位置都找不到它。 The output from the above gives me the path of where the file should be,but it's not there. 上面的输出为我提供了文件应位于的路径,但它不存在。

I'm using almost the exact block of code in another part for jpg files that I upload to the same directory and that works fine. 我将另一部分中几乎完全相同的代码块用于上载到同一目录的jpg文件,并且工作正常。

Any help/ideas are greatly appreciated. 任何帮助/想法,我们将不胜感激。

at first as I see you are calling method do_upload twice, I think you need to delete one of them. 首先,我看到您在两次调用方法do_upload,我认为您需要删除其中一个。 after do_upload call try to call $this->upload->display_errors() method it can give you some errors. 在do_upload调用之后,尝试调用$ this-> upload-> display_errors()方法可能会给您一些错误。 recheck the field name it should be "certificate" and check the chmod of './assets/certificates/' it should be 777. hope this helps. 重新检查字段名称,它应该是“ certificate”,并检查“ ./assets/certificates/”的chmod,它应该是777。希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM