-
-
Save Molaron/ab4b93337ccb7b9eb88591c4a2e49e02 to your computer and use it in GitHub Desktop.
This file contains 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 | |
$domain = "meinedomain.de"; | |
function generateRandomString($length = 10) { | |
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
$charactersLength = strlen($characters); | |
$randomString = ''; | |
for ($i = 0; $i < $length; $i++) { | |
$randomString .= $characters[rand(0, $charactersLength - 1)]; | |
} | |
return $randomString; | |
} | |
$target_dir = generateRandomString(8); | |
while(is_dir($target_dir)) | |
{ | |
$target_dir = generateRandomString(8); | |
} | |
$target_dir = ("gyazo/" . $target_dir . "/"); | |
$file_name = basename($_FILES["imagedata"]["name"]); | |
$target_file = $target_dir . $file_name; | |
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); //used to determine what kind of index.php we need | |
$placeholder = "Image.php"; | |
if($imageFileType == "mp4") { | |
$placeholder = "Video.php"; | |
} | |
$file_name = generateRandomString(16) . "." . $imageFileType; | |
$target_file = $target_dir . $file_name; | |
// Output JSON | |
function outputJSON($msg, $status = 'error'){ | |
die($domain . "/?error=" . $msg); | |
} | |
// Check for errors | |
if($_FILES['imagedata']['error'] > 0){ | |
outputJSON('An error ocurred when uploading.'); | |
} | |
if($_FILES["imagedata"]["size"] > 1.342e+8){ //2gb | |
outputJSON('That file is to big!'); | |
} | |
mkdir($target_dir); | |
// Upload file | |
if(!move_uploaded_file($_FILES['imagedata']['tmp_name'], $target_file)){ | |
outputJSON('Error uploading file - check destination is writeable.'); | |
} | |
$contents = file_get_contents("Placeholders/" . $placeholder); | |
if($placeholder == "Image.php") { | |
$image_info = getimagesize($target_file); | |
$image_width = $image_info[0]; | |
$image_height = $image_info[1]; | |
$contents = str_ireplace("%width%",$image_width,$contents); | |
$contents = str_ireplace("%height%",$image_height,$contents); | |
} | |
$contents = str_ireplace("%filename%",$file_name,$contents); | |
$fp = fopen($target_dir . "index.php","wb"); | |
fwrite($fp,$contents); | |
fclose($fp); | |
// Success! | |
echo "$domain/$target_dir"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment