function changefolder($ordner) { global $folders, $tnwidth, $gmwidth, $gdlibchecked; // set initial variable $ordner if (!isset($ordner)) { $ordner = $folders['previews'][0]->dir->src; } $ordner = '../../' . $ordner; $files_to_zip = array(); // scanning directories for image files if (is_dir($ordner)) { $dirhandle = opendir($ordner); $images = array(); $gdlibchecked = false; while ($filename = readdir($dirhandle)) { if (!isdot($filename) && is_file($ordner . '/' . $filename) && isvalidfiletype($filename)) { // image data $thumbnail = changetoroot($ordner . '/thumbnails/tn_' . $filename); $image = new Path($filename, changetoroot($ordner . '/' . $filename)); $files_to_zip[] = $ordner . '/' . $filename; $exif = null; // extract exif data $gps = getGPS($ordner . '/' . $filename); if (isset($gps)) { $gmthumbnail = changetoroot($ordner . '/thumbnails/gm_' . $filename); $exif = new Exif($gps, null, $gmthumbnail); } array_push($images, new Image($image, $thumbnail, $exif)); // create thumbs if necessary createthumb($ordner, 'tn', $filename, $tnwidth); createthumb($ordner, 'gm', $filename, $gmwidth); } } sort($images); $dir = new Path(preg_replace('/^(.+\\/)*/', '', $ordner), $ordner); closedir($dirhandle); } else { return null; } $gallery = new Gallery($images, $dir); create_zip($files_to_zip, '../../' . $gallery->download); return $gallery; }
// フォーム定義の最大サイズ超過 throw new RuntimeException('ファイルサイズが大きすぎます'); default: throw new RuntimeException('その他のエラーが発生しました'); } if (!in_array($type = @exif_imagetype($_FILES['image']['tmp_name']), array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG), true)) { throw new RuntimeException('画像形式が未対応です'); } $filename = sha1($_FILES['image']['tmp_name'] . date("Y/m/d (D) H:i:s", time()) . rand()); if (!move_uploaded_file($_FILES['image']['tmp_name'], $path = sprintf('./images/%s%s', $filename, image_type_to_extension($type)))) { throw new RuntimeException('ファイル保存時にエラーが発生しました'); } chmod($path, 0644); $msg = array('green', 'ファイルは正常にアップロードされました'); $exif = exif_read_data($path); $mapValue = getGPS($exif); /* DBに登録 */ $sql = "INSERT INTO images (\n user_id, path, caption, geo_lat, geo_long, width, height, created_at, modifed_at\n ) VALUES (\n 1001, :path, 'テスト', :geo_lat, :geo_long, :width, :height, null, now());"; $stmt = $dbh->prepare($sql); $stmt->bindParam(':path', $path); $stmt->bindParam(':geo_lat', $mapValue[0]); $stmt->bindParam(':geo_long', $mapValue[1]); $stmt->bindParam(':width', $exif['COMPUTED']['Width']); $stmt->bindParam(':height', $exif['COMPUTED']['Height']); $stmt->execute(); } catch (RuntimeException $e) { $msg = array('red', $e->getMessage()); } } function getGPS($exif) {
<?php require_once __DIR__ . '/../../../carbon/core.ini.php'; require_once __DIR__ . '/../../../carbon/requests/requests.inc.php'; require_once __DIR__ . '/../../../carbon/responses/responses.inc.php'; require_once __DIR__ . '/../../../carbon/formats/formats.inc.php'; require_once __DIR__ . '/../../../src/restaurant/restaurant.php'; try { $db = $config->getDefaultDatabase()->open(); $deliveryInfo = ['delivery_man_id' => Request::REQUIRED, 'order_number' => Request::REQUIRED]; $request = new StandardRequest(); $deliveryInfo = $request->extract($deliveryInfo); $deliveryInfo = arrayToJSONObject($deliveryInfo); $response = getGPS($db, $deliveryInfo); } catch (Exception $ex) { $response = new ExceptionResponse($ex); } $response = new JSONPrettyFormat($response); $response->present();