From 1851c3a180eafb4563a9f6e4dd40fcc5e925896a Mon Sep 17 00:00:00 2001 From: Horus3 Date: Sun, 5 Oct 2014 22:00:36 +0200 Subject: Experimental support for image uploading. --- foto/upload.php | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 foto/upload.php (limited to 'foto/upload.php') diff --git a/foto/upload.php b/foto/upload.php new file mode 100644 index 0000000..e8d1549 --- /dev/null +++ b/foto/upload.php @@ -0,0 +1,57 @@ + $tmp_name ){ + if ( $_FILES["images"]["error"][$f] == 4 ) + // no file was uploaded + continue; + + if ( $_FILES["images"]["error"][$f] != 0 ){ + continue; + } + if ( $_FILES["images"]["size"][$f] > IMAGE_MAXSIZE ){ + $message[$count] = $_FILES["images"]["name"][$f] . " is too large!"; + $count++; + continue; + } elseif ( ! in_array( pathinfo($_FILES["images"]["name"][$f], PATHINFO_EXTENSION), $extension ) ){ + $message[$count] = $_FILES["images"]["name"][$f] . " - Extension not allowed!"; + $count++; + continue; + } + $hash = hash_file("md5", $tmp_name); + + $sql = $db->prepare("INSERT INTO " . DBPREFIX . "image (id, gallery, name, desc, owner, mime, size, hash, time) VALUES (NULL, %s, %s, %s, %d, %s, %d, %s, %d);", $_POST["gallery"], $_FILES["images"]["name"][$f], "", $_SESSION["userid"], $_FILES["images"]["mime"][$f], $_FILES["images"]["size"][$f], $hash, time()); + + if ( ! file_exists(IMAGE_PATH . $hash . ".gz") ){ + move_uploaded_file($tmp_name, IMAGE_PATH . $hash); + + $gzfile = IMAGE_PATH . $hash . ".gz"; + $fp = gzopen($gzfile, "w9"); + + if ( ! gzwrite($fp, file_get_contents(IMAGE_PATH . $hash)) ) + exit; + + if ( ! gzclose($fp) ) + exit; + + if ( ! unlink(IMAGE_PATH . $hash) ) + exit; + } + + if ( ! $db->doQuery($sql) ) + exit; +} -- cgit v1.2.3