Create a gist now

Instantly share code, notes, and snippets.

anonymous /index.php
Created Dec 20, 2015

What would you like to do?
<?php
header("Content-Type: text/text");
############################################################################
# Simple PHP Upload Script for ShareX v0.1
# Copyright (C) 2013 Richard Cornwell
# Website: http://thegeekoftheworld.com/
# Script: http://thegeekoftheworld.com/using-a-php-upload-script-for-sharex/
# Email: richard@techtoknow.net
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses>.
############################################################################
function get_link()
{
#Change this to change how long a link you want to generate.
$length_of_link = 5;
$link = "";
$works = false;
while (!$works)
{
$link = substr(base64_encode(md5(rand())),0,$length_of_link);
if (empty(glob(getcwd() . "/" . $link . ".*")))
{
$works = true;
}
}
return $link;
}
$key = "CHANGEME";
$uploadhost = "http://upload.domain.tld/";
$redirect = "http://domain.tld/";
#Comment this next line if you want Robots to index this site.
if ($_SERVER["REQUEST_URI"] == "/robot.txt") { die("User-agent: *\nDisallow: /"); }
#Don't edit past this point!
if (isset($_POST['k'])) {
if ($_POST['k'] == $key) {
$link = get_link();
$target = getcwd() . "/" . $link . "." . strtolower(end(explode(".", $_FILES["d"]["name"])));
if (move_uploaded_file($_FILES['d']['tmp_name'], $target)) {
echo $uploadhost . $link . "." . end(explode(".", $_FILES["d"]["name"]));
} else {
echo "Sorry, there was a problem uploading your file.";
}
} else {
header('Location: '.$redirect);
}
} else {
header('Location: '.$redirect);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment