Created
June 13, 2016 16:01
-
-
Save nprussell/643623d208583598cf7e06c07a96d6b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$target_dir = "uploads/"; | |
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); | |
$uploadOk = 1; | |
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); | |
// Check if image file is a actual image or fake image | |
if(isset($_POST["submit"])) { | |
// Check if file already exists | |
if (file_exists($target_file)) { | |
echo "Sorry, file already exists."; | |
$uploadOk = 0; | |
} | |
// Check if $uploadOk is set to 0 by an error | |
if ($uploadOk == 0) { | |
echo "Sorry, the file was not uploaded."; | |
// if everything is ok, try to upload file | |
} else { | |
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { | |
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; | |
} else { | |
echo "Sorry, there was an error uploading your file."; | |
} | |
} | |
} else{ | |
echo "no post data"; | |
} | |
echo "<br><br>"; | |
//$uploadedFile = "uploads/out.upz"; | |
$handle = fopen($target_file, 'rb'); | |
if( ! $handle ) { | |
throw new Exception( "Can't open file" ); | |
} | |
$buffer = fread( $handle, 14 ); | |
while (($read = fgetc($handle)) !== "\0") { | |
$buffer .= $read; | |
} | |
$header_format = | |
'a3Magic/' . | |
'v1UpdaterVer/' . | |
'C1TestingMode/' . | |
'V2BuildTime/' . | |
'a*BuildVersion' ; | |
$header = unpack ($header_format, $buffer); | |
$magic = $header['Magic']; | |
$upVer = $header['UpdaterVer']; | |
$testM = $header['TestingMode']; | |
$buildTime64 = $header['BuildTime1'] + ($header['BuildTime2'] * 0x100000000); | |
$buildVer = $header['BuildVersion']; | |
include 'db.php'; | |
$id = hash('sha1', $header); | |
$git = $_POST['git']; | |
//$live = $_POST['live']; | |
$query = $connection->prepare(" | |
INSERT INTO versions(id,version,time,testing,updaterVersion,git) | |
VALUES (:id, :version, :time, :testing, :updaterVersion, :git) | |
"); | |
try { | |
$query->execute([ | |
'id'=>$id, | |
'version'=>$buildVer, | |
'time'=>$buildTime64, | |
'testing'=>$testM, | |
'updaterVersion'=>$upVer, | |
'git'=>$git | |
]); | |
//header("Location: ../version.php"); | |
echo "Query Executed"; | |
} catch (PDOException $e) { | |
die("Query failed"); | |
} | |
fclose( $handle ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment