Ejemplo n.º 1
0
 public function saveFileToDB($filepath, $userid)
 {
     ini_set('exif.encode_unicode', 'UTF-8');
     error_log($filepath);
     try {
         try {
             $exif_ifd0 = read_exif_data($filepath, 'IFD0', 0);
             $exif_exif = read_exif_data($filepath, 'EXIF', 0);
             $exif_file = read_exif_data($filepath, 'FILE', 0);
         } catch (Exception $e) {
         }
         $timetaken = null;
         $filename = $exif_file['FileName'];
         if (isset($exif_exif['DateTimeOriginal'])) {
             //We get the date and time the picture was taken
             try {
                 $exif_date = $exif_exif['DateTimeOriginal'];
                 error_log("EXIF TIME TAKEN : " . $exif_date);
                 $exif_timetaken = date("Y-m-d H:i:s", strtotime($exif_date));
             } catch (Exception $e) {
                 error_log($e->getMessage());
             }
         }
         if (isset($exif_ifd0['DateTime'])) {
             //We get the date and time the picture was taken
             try {
                 $ifd0_date = $exif_ifd0['DateTime'];
                 error_log("IFDO TIME TAKEN : " . $ifd0_date);
                 $ifd0_timetaken = date("Y-m-d H:i:s", strtotime($ifd0_date));
             } catch (Exception $e) {
                 error_log($e->getMessage());
             }
         }
         //We chose the earliest date of the 2
         if (isset($exif_date) && isset($ifd0_date)) {
             $rawTimeTaken = $exif_date < $ifd0_date ? $exif_date : $ifd0_date;
             error_log("FINAL TIME TAKEN : " . $rawTimeTaken);
             $timetaken = date("Y-m-d H:i:s", strtotime($rawTimeTaken));
         } else {
             if (isset($exif_date)) {
                 $rawTimeTaken = $exif_date;
                 error_log("FINAL TIME TAKEN : " . $rawTimeTaken);
                 $timetaken = date("Y-m-d H:i:s", strtotime($rawTimeTaken));
             } else {
                 if (isset($ifd0_date)) {
                     $rawTimeTaken = $ifd0_date;
                     error_log("FINAL TIME TAKEN : " . $rawTimeTaken);
                     $timetaken = date("Y-m-d H:i:s", strtotime($rawTimeTaken));
                 } else {
                     $rawTimeTaken = $exif_file['FileDateTime'];
                     $timetaken = date("Y-m-d H:i:s", $rawTimeTaken);
                 }
             }
         }
         error_log("TIME TAKEN : " . $timetaken);
         $fileType = $exif_file['MimeType'];
         //$payload = file_get_contents($filepath);
         $picture = new Picture(0, "", "", $timetaken, $fileType, null, $filename);
         $picture->latitude = "";
         $picture->longitude = "";
         $dao = new PictureDAO();
         $dayId = $dao->createDay($userid, $timetaken);
         $dao->savePicture($dayId, $picture);
         error_log("File saved successfully.");
         //unlink($filepath);
     } catch (Exception $e3) {
         print "Error!: " . $e3->getMessage() . "<br/>";
         //unlink($filepath);
     }
 }
Ejemplo n.º 2
0
 private function saveFileToDB($filepath)
 {
     ini_set('exif.encode_unicode', 'UTF-8');
     error_log($filepath);
     try {
         try {
             $exif_ifd0 = read_exif_data($filepath, 'IFD0', 0);
             $exif_exif = read_exif_data($filepath, 'EXIF', 0);
             $exif_file = read_exif_data($filepath, 'FILE', 0);
         } catch (Exception $e) {
         }
         var_dump($exif_ifd0);
         var_dump($exif_exif);
         $timetaken = null;
         $filename = $exif_file['FileName'];
         if (isset($exif_exif['DateTimeOriginal'])) {
             //We get the date and time the picture was taken
             try {
                 $exif_date = $exif_exif['DateTimeOriginal'];
                 error_log("EXIF TIME TAKEN : " . $exif_date);
                 $exif_timetaken = date("Y-m-d H:i:s", strtotime($exif_date));
             } catch (Exception $e) {
                 error_log($e->getMessage());
             }
         }
         if (isset($exif_ifd0['DateTime'])) {
             //We get the date and time the picture was taken
             try {
                 $ifd0_date = $exif_ifd0['DateTime'];
                 error_log("IFDO TIME TAKEN : " . $ifd0_date);
                 $ifd0_timetaken = date("Y-m-d H:i:s", strtotime($ifd0_date));
             } catch (Exception $e) {
                 error_log($e->getMessage());
             }
         }
         //We chose the earliest date of the 2
         if (isset($exif_date) && isset($ifd0_date)) {
             $rawTimeTaken = $exif_date < $ifd0_date ? $exif_date : $ifd0_date;
             error_log("FINAL TIME TAKEN : " . $rawTimeTaken);
             $timetaken = date("Y-m-d H:i:s", strtotime($rawTimeTaken));
         } else {
             if (isset($exif_date)) {
                 $rawTimeTaken = $exif_date;
                 error_log("FINAL TIME TAKEN : " . $rawTimeTaken);
                 $timetaken = date("Y-m-d H:i:s", strtotime($rawTimeTaken));
             } else {
                 if (isset($ifd0_date)) {
                     $rawTimeTaken = $ifd0_date;
                     error_log("FINAL TIME TAKEN : " . $rawTimeTaken);
                     $timetaken = date("Y-m-d H:i:s", strtotime($rawTimeTaken));
                 } else {
                     $rawTimeTaken = $exif_file['FileDateTime'];
                     $timetaken = date("Y-m-d H:i:s", $rawTimeTaken);
                 }
             }
         }
         error_log("TIME TAKEN : " . $timetaken);
         $fileType = $exif_file['MimeType'];
         /* $exif = exif_read_data($filepath, 'IFD0');
          		 foreach ($exif as $key => $section) {
          		foreach ($section as $name => $val) {
          		error_log("$key.$name: $val");
          		}
          		} */
         //Reduce file size
         $img = imagecreatefromjpeg($filepath);
         $quality = 100;
         $currentFileSize = filesize($filepath);
         switch ($currentFileSize) {
             case $currentFileSize > 3000000:
                 $quality = 7;
                 break;
             case $currentFileSize > 2000000:
                 $quality = 14;
                 break;
             case $currentFileSize > 1000000:
                 $quality = 21;
                 break;
             case $currentFileSize > 500000:
                 $quality = 70;
                 break;
         }
         imagejpeg($img, $filepath, $quality);
         imagedestroy($img);
         //$payload = file_get_contents($filepath);
         $picture = new Picture(0, "", "", $timetaken, $fileType, null, $filename);
         $picture->latitude = "";
         $picture->longitude = "";
         $dao = new PictureDAO();
         if (isset($_SESSION['name'])) {
             $userid = $_SESSION["userid"];
             $dayId = $dao->createDay($userid, $timetaken);
             $dao->savePicture($dayId, $picture);
         } else {
             error_log("COULD NOT SAVE PICTURES, NO USER IN SESSION!!!");
             unlink($filepath);
         }
         //unlink($filepath);
     } catch (Exception $e3) {
         print "Error!: " . $e3->getMessage() . "<br/>";
         unlink($filepath);
     }
 }
Ejemplo n.º 3
0
 private function saveFileToDB($filepath)
 {
     ini_set('exif.encode_unicode', 'UTF-8');
     error_log($filepath);
     try {
         try {
             $exif_ifd0 = read_exif_data($filepath, 'IFD0', 0);
             $exif_exif = read_exif_data($filepath, 'EXIF', 0);
             $exif_file = read_exif_data($filepath, 'FILE', 0);
         } catch (Exception $e) {
         }
         $timetaken = null;
         $filename = $exif_file['FileName'];
         if (isset($exif_ifd0['DateTime'])) {
             //We get the date and time the picture was taken
             try {
                 $rawTimeTaken = $exif_ifd0['DateTime'];
                 error_log("IFDO TIME TAKEN : " . $rawTimeTaken);
                 $timetaken = date("Y-m-d H:i:s", strtotime($rawTimeTaken));
             } catch (Exception $e) {
             }
         } else {
             if (isset($exif_exif['DateTimeOriginal'])) {
                 //We get the date and time the picture was taken
                 try {
                     $rawTimeTaken = $exif_exif['DateTimeOriginal'];
                     error_log("EXIF TIME TAKEN : " . $rawTimeTaken);
                     $timetaken = date("Y-m-d H:i:s", strtotime($rawTimeTaken));
                 } catch (Exception $e) {
                 }
             } else {
                 $rawTimeTaken = $exif_file['FileDateTime'];
                 $timetaken = date("Y-m-d H:i:s", $rawTimeTaken);
             }
         }
         error_log("NEW TIME TAKEN : " . $timetaken);
         $fileType = $exif_file['MimeType'];
         /* $exif = exif_read_data($filepath, 'IFD0');
          			foreach ($exif as $key => $section) {
          		foreach ($section as $name => $val) {
          		error_log("$key.$name: $val");
          		}
          		} */
         //Reduce file size
         $img = imagecreatefromjpeg($filepath);
         $quality = 100;
         $currentFileSize = filesize($filepath);
         switch ($currentFileSize) {
             case $currentFileSize > 3500000:
                 $quality = 15;
                 break;
             case $currentFileSize > 2000000:
                 $quality = 30;
                 break;
             case $currentFileSize > 1000000:
                 $quality = 60;
                 break;
             case $currentFileSize > 500000:
                 $quality = 70;
                 break;
         }
         imagejpeg($img, $filepath, $quality);
         imagedestroy($img);
         $payload = file_get_contents($filepath);
         $picture = new Picture(0, "", "", $timetaken, $fileType, $payload, $filename);
         $picture->latitude = "";
         $picture->longitude = "";
         $dao = new PictureDAO();
         $dayId = $dao->createDay(1, $timetaken);
         $dao->savePicture($dayId, $picture);
         unlink($filepath);
     } catch (Exception $e) {
         error_log("Exception!!! --- " . $e);
         //unlink($filepath);
     }
 }
Ejemplo n.º 4
0
                break;
            case $currentFileSize > 1000000:
                $quality = 21;
                break;
            case $currentFileSize > 500000:
                $quality = 50;
                break;
        }
        imagejpeg($img, $filepath, $quality);
        imagedestroy($img);
        $payload = file_get_contents($filepath);
        $picture = new Picture(0, "", "", $timetaken, $fileType, $payload, $filename);
        $picture->latitude = "";
        $picture->longitude = "";
        $dao = new PictureDAO();
        error_reporting(E_ERROR | E_PARSE);
        session_start();
        if (isset($_SESSION['name'])) {
            $userid = $_SESSION["userid"];
            $dayId = $dao->createDay($userid, $timetaken);
            $dao->savePicture($dayId, $picture);
        } else {
            error_log("COULD NOT SAVE PICTURES, NO USER IN SESSION!!!");
        }
        //unlink($filepath);
    } catch (Exception $e) {
        error_log("Exception!!! --- " . $e);
        unlink($filepath);
    }
}
header("Location: index.php");