1

I am stuck here.. I was trying to upload image and video, image upload working fine but while uploading video getting the error as "The filetype you are attempting to upload is not allowed.". I have tried all the answers but unfortunately couldn't workout. Can someone plz help me. What Am I doing wrong? Thanks.

My View 'home':

        <div style="margin-right: 17px;">
            <label>Name:</label>
            <input type="text" name="name" value="<?php echo set_value('name');?>">
            <?php echo form_error('name','<div class="error">','</div>'); ?>
        </div>
        <div style="padding:20px 20px">
            <label>Upload Image</label>
            <input type="file" name="photo">
        </div>
        <div style="padding:5px 5px">
            <label>Upload Video</label>
            <input type="file" name="video">
        </div>
        <div style="padding:10px 10px">
            <input type="submit" name="sumit" value="Submit">
        </div>
    </form>

My Controller:

$this->form_validation->set_rules('name', 'Name', 'trim|required');

    if(! $this->form_validation->run()){
        $data['useradded'] = "";
    }
    else{

        if(isset($_FILES['photo']['tmp_name'])){

            $config['upload_path'] = "./uploads/complaints/";
            $config['allowed_types'] = "jpg|png|gif";
            $config['max_size']     = '2048';
            $config['max_width'] = '0';
            $config['max_height'] = '0';
            $new_name = "photo_" . rand();
            $config['file_name'] = $new_name;
            $this->load->library('upload', $config);

            if(! $this->upload->do_upload('photo')){
                $data['error'] = array('error' => $this->upload->display_errors());
                $photo_name = "";
            }else{
                $photo_name = $new_name; 
            }

        }
        if(isset($_FILES['video']['tmp_name'])){

            $config['upload_path'] = "./uploads/complaints/videos/";
            $config['allowed_types'] = "avi|flv|wmv|mpg|mpeg|mp3|mp4";
            //$config['allowed_types'] = "video/x-msvideo|image/jpeg|video/mpeg|video/x-ms-wmv";
            $config['max_size']     = '0';
            $new_name = "video_" . rand();
            $config['file_name'] = $new_name;
            $this->load->library('upload', $config);

            if(! $this->upload->do_upload('video')){
                $data['error'] = array('error' => $this->upload->display_errors());
                $video_name = "";
            }else{
                $video_name = $new_name;
            }

        }
        $this->complaints_model->add_complaint($photo_name,$video_name);
        $data['useradded'] = "New complaint added Successfully";
    }
    $this->load->view('home', $data);
Prasad Patel
  • 707
  • 3
  • 16
  • 53
  • What's your video file format? – Panda Feb 13 '16 at 08:59
  • It can upload any video formats like "wmv, avi, mp4, etc". I have tried uploading wmv and mp4. I set "post_max_size=100M" and "upload_max_filesize=100M" in "php.ini" file and have also added these lines in "mimes.php" 'wmv' => array('video/wmv', 'video/x-ms-wmv', 'flv-application/octet-stream', 'application/octet-stream'), 'flv' => array('video/flv', 'video/x-flv', 'flv-application/octet-stream', 'application/octet-stream'), 'mp4' => 'video/mp4', '3gp' => 'video/3gpp' but doesn't workout. – Prasad Patel Feb 13 '16 at 09:15
  • I got the solution from below link in Stackoverflow. Thanks. http://stackoverflow.com/questions/9815208/codeigniter-the-filetype-you-are-attempting-to-upload-is-not-allowed – Prasad Patel Feb 17 '16 at 10:00

0 Answers0