Exemplo n.º 1
0
 function uploadScreenshots($shots = "")
 {
     if (!empty($_POST['ajax'])) {
         $shots = $_FILES['shot'];
     }
     $app_id = $this->input->post('app_id');
     $title = str_replace(" ", "", $this->input->post('title')) != "" ? str_replace(" ", "", $this->input->post('title')) : NULL;
     if (!empty($shots)) {
         $i = 1;
         if (!empty($_POST['nushot'])) {
             $count = $this->screenshot->count_all("WHERE `app_id`={$app_id}");
             $i = $count['COUNT(*)'] + 1;
         }
         foreach ($shots['error'] as $key => $value) {
             if ($value == UPLOAD_ERR_OK) {
                 //continue
                 $tmp_name = $shots['tmp_name'][$key];
                 $name = basename($shots["name"][$key]);
                 $name = str_replace(" ", "", $name);
                 $ext = strtolower(strrchr($name, "."));
                 if ($ext != ".jpg" && $ext != ".jpeg" && $ext != ".png" && $ext != ".gif") {
                     $uploaded[] = "Invalid image format.";
                 } else {
                     //continue
                     if ($title != NULL) {
                         $dest_name = "scr_" . $title . "_" . $i . $ext;
                     } else {
                         $dest_name = "scr_" . $i . $ext;
                     }
                     $i++;
                     $destination = "screenshots/" . $dest_name;
                     if (move_uploaded_file($tmp_name, $destination)) {
                         $uploaded[] = $dest_name;
                         $screenshot = new Screenshot();
                         $screenshot->name = base_url() . $destination;
                         $screenshot->app_id = $app_id;
                         $screenshot->create();
                     }
                 }
             } else {
                 $uploaded[] = $this->useful->upload_errors[$value];
             }
         }
         if (!empty($_POST['ajax'])) {
             echo json_encode($uploaded);
         }
     }
 }