From afc3e0f15e6c4e69d17fd5a84253a436a4fba4fc Mon Sep 17 00:00:00 2001 From: Peter Lejeck Date: Thu, 31 Oct 2013 05:01:18 -0700 Subject: Move upload.php into static dir, and do hardcore refactoring --- upload.php | 81 -------------------------------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 upload.php (limited to 'upload.php') diff --git a/upload.php b/upload.php deleted file mode 100644 index 5c611fc..0000000 --- a/upload.php +++ /dev/null @@ -1,81 +0,0 @@ - array(), "success" => true); - $files = $_FILES["files"]; - $num_files = count($files["name"]); - - for ($i = 0; $i < $num_files; $i++) { - //Check if file exists already - $filehash = sha1_file($files["tmp_name"][$i]); - $con = new PDO('mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=XXX', 'XXX', 'XXX'); - $do = $con->prepare("SELECT hash, filename FROM files WHERE hash = (:hash)"); - $do->bindParam(':hash', $filehash); - $do->execute(); - $result = $do->fetch(); - if($result[0]==$filehash){ - $out["files"][] = array( - "name" => $files["name"][$i], - "url" => $result[1] - ); - }else{ - $catshit = hash_file('crc32b', $files["tmp_name"][$i]); - $newname = generate_name($files["name"][$i], $catshit); - //Generate delid - $delid = sha1($files["tmp_name"][$i]); - //Try to upload and other shit - if ($newname && $files["error"][$i] == 0 && move_uploaded_file($files["tmp_name"][$i], $static_root.$newname)) { - //Insert info into DB - $do = $con->prepare("INSERT INTO files (hash, orginalname, filename, size, date, expire, delid) VALUES (:hash, :orginname, :filename, :size, :date, :expire, :delid)"); - $do->bindParam(':hash', $filehash); - $do->bindParam(':orginname', $files["name"][$i]); - $do->bindParam(':filename', $newname); - $do->bindParam(':size', $files["size"][$i]); - $do->bindParam(':date', date('Y-m-d')); - $do->bindParam(':expire', $expire); - $do->bindParam(':delid', $delid); - $do->execute(); - $out["files"][] = array( - "name" => $files["name"][$i], - "url" => $newname - ); - //Otherwise return error - } else { - http_response_code(500); - echo json_encode(array( - "success" => false - )); - } - } - } - $con = null; - exit(json_encode($out, JSON_PRETTY_PRINT)); -} - -if(isset($_FILES["files"])){ -upload(); -}else{ -exit("What ya doing here nigga?"); -} - - -?> -- cgit v1.2.3