Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't seem to upload css file types in codeigniter

I'm trying to upload a css file user codigniter's upload class. Here is the controller:

public function uploadcssfile() 
{
   $config['upload_path'] = './stylesheets/stores/'.$memberid.'/'; 
   $config['file_name'] = 'main.css';    
   $config['allowed_types'] = 'css';   
   $config['overwrite'] = true;   
   $this->load->library('upload', $config);
   if (! $this->upload->do_upload('filefieldname'))
   {
     die($this->upload->display_errors());
   } 
}

I just want to upload a file of type css, yet codeigniter always gives this error:

The filetype you are attempting to upload is not allowed.
like image 378
user1664427 Avatar asked Sep 12 '12 01:09

user1664427


People also ask

Where do I put CSS file in CodeIgniter?

Adding JavaScript and CSS (Cascading Style Sheet) file in CodeIgniter is very simple. You have to create JS and CSS folder in root directory and copy all the . js files in JS folder and . css files in CSS folder as shown in the figure.

How do I allow all files in CodeIgniter?

Upload any File – Codeigniter$this->upload->set_allowed_types('*'); Call the upload library first by using this->load->library('upload'). set allowed type to * will make any file upload in codeigniter.

How do I upload a PDF in CodeIgniter?

For Uploading files, as usually we need a Simple HTML form, with an input field and submit button. Here is the Code: 'file','name' => 'userfile')); echo form_submit('submit','upload'); echo form_close(); ?>


1 Answers

I know, this is really weird but it worked for me:

in application/config/mimes.php, line 77

'css' => 'text/css',

change to:

'css' => array('text/css','text/x-c'),

To see, if your development environment has its own sense of humour and can add new mime types to any text files (my case), check your mimes like this:

if ( ! $this->upload->do_upload(-your-form-input-name-) ){
                    print_r($_FILES['-your-form-input-name-']['type']);
                    exit($this->upload->display_errors(). 'File Type: ' . $this->upload->file_type);
                }

If an upload fails it will show you what mime type your server is actually getting to deal with.

PS. Now that there is an answer to your question, go here and help me :)

like image 197
pop Avatar answered Nov 03 '22 11:11

pop