$fd = finfo_open(); $info = finfo_buffer($fd, $img, FILEINFO_MIME_TYPE); finfo_close($fd); if (!strstr($info, "image/")) { $_POST['error'] = "No image file"; echo "Error file"; } else { $meme = prepare_posmeme($pos); unset($info, $cursor, $fd, $pos); $img = imagecreatefromstring($img); $img = imageresize($img, 320, 240); if (!$img) { $_POST['error'] = "Can't create image object"; echo "Error image object"; } else { $img = merge_to_finalimg($img, $meme); unset($meme); if (!$img) { $_POST['error'] = "Merged failed"; echo "Error merge"; } else { $trans = 0; try { $pdo = new PDO($DB_DSN, $DB_USER, $DB_PASSWORD); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->exec("USE db_camagru;"); $sql = "SELECT `id` FROM users WHERE `login` = :login;"; $pre = $pdo->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)); $pre->execute(array('login' => $_SESSION['logged_on_us'])); $ret = $pre->fetchAll(); if (!isset($ret[0]['id'])) {
$_POST['error'] = "No user logged"; echo "Error log"; } else { if (!isset($_POST['image']) || !isset($_POST['pos']) || !isset($_POST['tag'])) { $_POST['error'] = "Post not set"; echo "Error request"; } else { $tag = htmlspecialchars($_POST['tag']); $pic64 = $_POST['image']; $pos = htmlspecialchars($_POST['pos']); $file_name = hash("md5", time() . rand()); $image = get_imagefrompict($pic64, $file_name, "../images/"); unset($pic64); if ($image !== FALSE) { $meme = prepare_posmeme($pos); $image = merge_to_finalimg($image, $meme); unset($meme, $pos); if ($image !== FALSE) { if (image_puttofilepng($image, $file_name, "../images/") !== FALSE) { if (image_resized($file_name, "../images/", "../resized/", 0.5) !== FALSE) { $trans = 0; unset($image); try { $pdo = new PDO($DB_DSN, $DB_USER, $DB_PASSWORD); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->exec("USE db_camagru;"); $sql = "SELECT `id` FROM users WHERE `login` = :login;"; $pre = $pdo->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)); $pre->execute(array("login" => $_SESSION['logged_on_us'])); $ret = $pre->fetchAll(); if (!isset($ret[0]['id'])) {