![]() |
Upload Error: The filetype you are attempting to upload is not allowed. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Upload Error: The filetype you are attempting to upload is not allowed. (/showthread.php?tid=37558) |
Upload Error: The filetype you are attempting to upload is not allowed. - El Forum - 01-13-2011 [eluser]Unknown[/eluser] I get this error whenever trying to upload any jpg or png image file. My form: <form action="/merchant/process_create" method="post" id="merchant_signup" enctype="multipart/form-data"> <?php echo form_label('Select Your Logo or Relevant Image:', 'image'); echo "<br />"; ?> <input type="file" name="image" size="20" id="image" /> echo form_submit('submit', 'Create Account'); ?> The upload part of the controller: //upload the image $config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . '/uploads/'; $config['allowed_types'] = 'jpg|jpeg|gif|png'; $config['max_size'] = '2000'; $config['max_width'] = '0'; $config['max_height'] = '0'; $config['file_name'] = time() . rand(); $config['remove_spaces'] = TRUE; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('image')) { $data= array('error' => $this->upload->display_errors('', '<br />')); //reload the view $this->load->view('header'); $this->load->view('merchant_create_form', $data); $this->load->view('footer'); } else { //make the insert array $merchant_data = array( 'user_id' => $this->session->userdata('user_id'), 'name' => $this->input->post('name'), 'uri_slug' => $this->input->post('uri_slug'),...... I have no clue what i'm doing wrong, please help. Thanks! Nick Upload Error: The filetype you are attempting to upload is not allowed. - El Forum - 01-13-2011 [eluser]Cristian Gilè[/eluser] From the userguide, the description for the file_name setting says: Quote:If set CodeIgniter will rename the uploaded file to this name. The extension provided in the file name must also be an allowed file type. Change your actual $config['file_name'] to: Code: $config['file_name'] = rand().time().get_extension($_FILES['image']['name']); You can use a function like this to get the extension: Code: function get_extension($filename) Cristian Gilè Upload Error: The filetype you are attempting to upload is not allowed. - El Forum - 01-13-2011 [eluser]Unknown[/eluser] That worked great. Thanks so much!! |