public function __construct(Stor $stor, $width = null) { $this->type = $stor->getType(); $this->content = $stor->getContent(); $this->filename = "var/tempthumb" . generateRandomChars(4, "0123456789"); if (!isset($width)) { $this->width = self::DEFAULT_WIDTH; } else { $this->width = $width; } $this->make(); }
if (!isset($_REQUEST['token']) || empty($_REQUEST['token'])) { header("HTTP/1.1 400 Bad Request"); echo "<span style=\"color: red; font-weight: bold; font-size: 24pt;\">400 Bad Request</span><br />"; echo "<br />"; echo "Your browser sent a request that could not be understood."; exit; } if (!isset($_REQUEST['size']) || empty($_REQUEST['size'])) { $width = null; } else { $width = $_REQUEST['size']; } if (file_exists("var/tokn/" . $_REQUEST['token'])) { $token = new ToknFile($_REQUEST['token']); if (file_exists("var/stor/" . $token->getReference())) { $stor = new Stor(new StorFromFile("var/stor/" . $token->getReference())); $thumbnail = new Thumbnail($stor, $width); header("Content-Disposition: inline"); header("Content-Type: " . $stor->getType()); header("Content-Length: " . $thumbnail->size()); set_time_limit(0); print $thumbnail->raw(); exit; } else { header("HTTP/1.1 410 Gone"); echo "<span style=\"color: red; font-weight: bold; font-size: 24pt;\">410 Gone</span><br />"; echo "<br />"; echo "The requested URL is no longer available on this server."; exit; } } else {
echo "\t\t\t\t<th>Retrieve URL</th>\n"; echo "\t\t\t\t<th>Delete URL</th>\n"; echo "\t\t\t</tr>\n"; echo "\t\t\t<tr>\n"; echo "\t\t\t\t<td></td>\n"; echo "\t\t\t\t<td></td>\n"; echo "\t\t\t\t<td></td>\n"; echo "\t\t\t\t<td>(Share this link to whom you want. This will let them see the upload.)</td>\n"; echo "\t\t\t\t<td>(Use this link to delete your upload. " . "<span style=\"color: red; font-weight: bold;\">WARNING! This URL is only shown " . "to you once! If you lose it, you lose the ability to delete the file!</span>)</td>\n"; echo "\t\t\t</tr>\n"; for ($i = 0; $i < count($_FILES['images']['name']); $i++) { echo "\t\t\t<tr>\n"; $allowed_types = array('image/jpeg', 'image/png', 'image/gif'); if (in_array($_FILES['images']['type'][$i], $allowed_types, true)) { $token = new ToknData(generateRandomChars(8), str_shuffle(sha1(time()))); $stor = new Stor(new StorFromData($_FILES['images']['name'][$i], $_FILES['images']['type'][$i], file_get_contents($_FILES['images']['tmp_name'][$i]))); if ($stor->getSize() !== $_FILES['images']['size'][$i]) { throw new Exception("Content and content size mismatch"); } $token->write(); $stor->write(new StorToFile("var/stor/" . $token->getReference())); $retrieve_url = str_replace(basename(__FILE__), "g/" . $token->getName(), selfURL()); $thumbnail = new Thumbnail($stor); $thumbnail_url = str_replace(basename(__FILE__), "t/" . $token->getName(), selfURL()); $delete_url = str_replace(basename(__FILE__), "d/" . $token->getName() . "/" . $stor->getSecretKey(), selfURL()); echo "\t\t\t\t<td>" . $_FILES['images']['name'][$i] . "</td>\n"; echo "\t\t\t\t<td style=\"color: darkgreen; font-weight: bold;\">Successfully uploaded</td>\n"; echo "\t\t\t\t<td><a href=\"{$thumbnail_url}\" target=\"_blank\">" . $thumbnail->html() . "</a></td>\n"; echo "\t\t\t\t<td><a href=\"{$retrieve_url}\" target=\"_blank\">{$retrieve_url}</a></td>\n"; echo "\t\t\t\t<td><a href=\"{$delete_url}\" target=\"_blank\">{$delete_url}</a></td>\n"; } else {
require_once "lib/Prosperia/bootstrap.php"; use Prosperia\Tokn\ToknFile; use Prosperia\Stor; use Prosperia\Stor\StorFromFile; define('PRINT_CHUNK_SIZE', 8192); if (!isset($_REQUEST['token']) || empty($_REQUEST['token'])) { header("HTTP/1.1 400 Bad Request"); echo "<span style=\"color: red; font-weight: bold; font-size: 24pt;\">400 Bad Request</span><br />"; echo "<br />"; echo "Your browser sent a request that could not be understood."; exit; } if (file_exists("var/tokn/" . $_REQUEST['token'])) { $token = new ToknFile($_REQUEST['token']); if (file_exists("var/stor/" . $token->getReference())) { $stor = new Stor(new StorFromFile("var/stor/" . $token->getReference())); header("Content-Disposition: inline"); header("Content-Type: " . $stor->getType()); header("Content-Length: " . $stor->getSize()); $location = 0; set_time_limit(0); while ($location <= $stor->getSize()) { print substr($stor->getContent(), $location, PRINT_CHUNK_SIZE); ob_flush(); flush(); $location += PRINT_CHUNK_SIZE; } exit; } else { header("HTTP/1.1 410 Gone"); echo "<span style=\"color: red; font-weight: bold; font-size: 24pt;\">410 Gone</span><br />";
require_once "lib/Prosperia/bootstrap.php"; use Prosperia\Tokn\ToknFile; use Prosperia\Stor; use Prosperia\Stor\StorFromFile; use Prosperia\Thumbnail; if (!isset($_REQUEST['token']) || empty($_REQUEST['token']) || !isset($_REQUEST['key']) || empty($_REQUEST['key'])) { header("HTTP/1.1 400 Bad Request"); echo "<span style=\"color: red; font-weight: bold; font-size: 24pt;\">400 Bad Request</span><br />"; echo "<br />"; echo "Your browser sent a request that could not be understood."; exit; } if (file_exists("var/tokn/" . $_REQUEST['token'])) { $token = new ToknFile($_REQUEST['token']); if (file_exists("var/stor/" . $token->getReference())) { $stor = new Stor(new StorFromFile("var/stor/" . $token->getReference())); if ($_REQUEST['key'] == $stor->getSecretKey()) { $thumbnail = new Thumbnail($stor); unlink("var/stor/" . $token->getReference()); unlink("var/tokn/" . $token->getName()); echo "<span style=\"color: red; font-weight: bold; font-size: 24pt;\">File deleted</span><br />"; echo "<br />"; echo $thumbnail->html(); echo "<br />"; echo "The image you wanted delete has been successfully deleted from the server."; exit; } else { header("HTTP/1.1 403 Forbidden"); echo "<span style=\"color: red; font-weight: bold; font-size: 24pt;\">403 Forbidden</span><br />"; echo "<br />"; echo "You don't have permission to access the requested resource.";