Codeigniter PDF File Upload

Codeigniter PDF File Upload


PDF File Upload Codeigniter Framework mostly discussed previously and this post is about uploading files in Codeigniter has upload library by using this class we can upload file on server very easily. Codeigniter session Storage

Codeigniter PDF File Upload
Codeigniter PDF File Upload


<?php
echo $error;
echo form_open_multipart('upload/do_upload');
echo form_input(array('type' => 'file','name' => 'userfile'));
echo form_submit('submit','upload');
echo form_close();
?>

Controller method you need to set some config setting like uploading path, allowed types, upload sizes, width height,... etc.

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

        $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>";
        }
}<?php

Library Codeigniter PDF File upload root directory Follows


Open <root_directory>/system/application/config/mimes.php file

Change value of ‘pdf’ element of $mimes array

$mimes = array( ‘hqx’   =>      ‘application/mac-binhex40’,
‘cpt’   =>      ‘application/mac-compactpro’,
‘csv’   =>      array(‘text/x-comma-separated-values’, ‘text/comma-separated-values’, ‘application/octet-stream’, ‘application/vnd.ms-excel’, ‘text/csv’, ‘application/csv’, ‘application/excel’, ‘application/vnd.msexcel’),
‘bin’   =>      ‘application/macbinary’,
‘dms’   =>      ‘application/octet-stream’,
‘lha’   =>      ‘application/octet-stream’,
‘lzh’   =>      ‘application/octet-stream’,
‘exe’   =>      ‘application/octet-stream’,
‘class’ =>      ‘application/octet-stream’,
‘psd’   =>      ‘application/x-photoshop’,
‘so’    =>      ‘application/octet-stream’,
‘sea’   =>      ‘application/octet-stream’,
‘dll’   =>      ‘application/octet-stream’,
‘oda’   =>      ‘application/oda’,
‘pdf’   =>      array(‘application/pdf’, ‘application/x-pdf’),

To

‘pdf’   =>      array(‘application/pdf’, ‘application/x-pdf’, ‘application/x-download’,’application/x-download’, ‘binary/octet-stream’, ‘application/unknown’, ‘application/force-download’),
Codeigniter PDF File Upload Dev2Tricks 5 of 5
Codeigniter PDF File Upload PDF File Upload Codeigniter Framework mostly discussed previously and this post is about uploading files i...

Share this

Related Posts

Previous
Next Post »

3 comments

comments
5 April 2016 at 06:01 delete

eh kutu kupret , screenshott ama tutorialnya beda , kemplu lau

Reply
avatar
1 May 2016 at 02:41 delete

Hello,

Can you explain in English. So that we will provide a solution for this.

Thanks

Reply
avatar
24 January 2017 at 17:50 delete

your sreenshoot diffrent with actual your coding man....

Reply
avatar