views:

92

answers:

2

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).

I'm trying to upload a PDF file, and I'm using the following code (codeigniter version 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.

Any help/ideas are greatly appreciated.

A: 

Can I see your code for the upload view, etc? I'm guessing the code you posted is the code for the controller method that handles the upload?

George
@george shouldn't that be a comment, not an "answer"? You're just asking for more information from the OP...
Matthew
Yeah, sorry, still new to SO and trying to get used to things. Thanks.
George
+1  A: 

Hi,

at first as I see you are calling method do_upload twice, I think you need to delete one of them. after do_upload call try to call $this->upload->display_errors() method it can give you some errors. recheck the field name it should be "certificate" and check the chmod of './assets/certificates/' it should be 777. hope this helps.

KoKo
oops, that was an error on my part when I was pasting in the code here, but your suggestions helped all the same, I added in the call to $this->upload->display_errors() and I got back some meaningful info, turns out the file was being rejected because it didn't think it was of the correct filetype, I searched a little more on this and found that this is a bug in codeigniter, I had to edit the mimes.php file under config to array('application/pdf', 'application/x-pdf','application/octet-stream')Thanks for all your help!
Felipe K