Skip to content

Instantly share code, notes, and snippets.

@ScruffyRules
Created January 11, 2015 21:19
Show Gist options
  • Save ScruffyRules/afc81e89e51bed741748 to your computer and use it in GitHub Desktop.
Save ScruffyRules/afc81e89e51bed741748 to your computer and use it in GitHub Desktop.
ShareX URL Shortener
RewriteEngine On
RewriteRule ^(?!.*\.php)(.*)$ go.php?jam=$1 [NC,L]
<?php
if(!isset($_GET['jam'])) {
header("HTTP/1.0 400 Bad Request");
die("HTTP/1.0 400 Bad Request");
}
if (!file_exists($_GET['jam'])) {
header("HTTP/1.0 400 Bad Request");
die("HTTP/1.0 400 Bad Request");
}
header("Location: ".file_get_contents($_GET['jam']));
die();
?>
{
"Name": "ScruffyRules.com_Shortener",
"RequestType": "POST",
"RequestURL": "http://scruffyrules.com/s/new.php",
"FileFormName": "",
"Arguments": {
"url": "$input$"
},
"ResponseType": "Text",
"RegexList": [],
"URL": "",
"ThumbnailURL": "",
"DeletionURL": ""
}
<?php
//Number of characters to be shown when a random file name is generated
$url_length = 6;
//URL which will be displayed after upload (URL will have the file name appended)
$url = "http://scruffyrules.com/s/";
if(!isset($_POST['url'])) {
header("HTTP/1.0 400 Bad Request");
die("HTTP/1.0 400 Bad Request");
}
$name = generateRandomString();
file_put_contents($name, $_POST['url']);
echo $url.$name;
function generateRandomString() {
global $url_length;
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $url_length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
?>
@dotziph
Copy link

dotziph commented Jan 15, 2020

you upload those files to your site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment