예제 #1
0
 public function post()
 {
     $data['message1'] = "";
     $data['message2'] = "";
     $data['message'] = "";
     $this->form_validation->set_rules('post_data', 'Post data', 'trim|required|max_length[800]|xxs_clean');
     if ($this->form_validation->run() == TRUE) {
         $post = new Post_info();
         $post->user_id = $this->session->userdata('user_id');
         $post->post_data = $this->input->post('post_data');
         $postObj = $post->addPost();
         if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
             foreach ($_FILES['files']['name'] as $f => $name) {
                 /* adding database information for image */
                 $imageData = new Image_info();
                 $imageData->user_id = $this->session->userdata('user_id');
                 $imageData->image_type = "post";
                 $imageData->id = $postObj->post_id;
                 $imageObj = $imageData->addImage();
                 /* uploading file on server file system */
                 $valid_formats = array("jpg", "jpeg", "png", "gif", "bmp");
                 $max_file_size = 1024 * 1024;
                 //1 mb
                 $path = "assets/sns_img";
                 $count = 0;
                 $ImageName = $path . "/" . $imageObj->image_id;
                 if ($_FILES['files']['error'][$f] == 4) {
                     continue;
                     // Skip file if any error found
                 }
                 if ($_FILES['files']['error'][$f] == 0) {
                     if ($_FILES['files']['size'][$f] > $max_file_size) {
                         $data['message1'] = "File too large";
                         continue;
                         // Skip large files
                     } elseif (!in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats)) {
                         $data['message1'] = $data['message1'] . " File extension unsupported";
                         continue;
                         // Skip invalid file formats
                     } else {
                         // No error found! Move uploaded files
                         if (move_uploaded_file($_FILES["files"]["tmp_name"][$f], $ImageName)) {
                             $count++;
                             // Number of successfully uploaded file
                             $data['message1'] = "posted successful";
                         }
                     }
                 }
             }
         }
         $url = base_url() . "user/index/" . $data['message1'];
         redirect($url, 'Location');
     }
 }