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 {
         echo "\t\t\t\t<td>" . $_FILES['images']['name'][$i] . "</td>\n";
Example #2
0
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 />";
        echo "<br />";
        echo "The requested URL is no longer available on this server.";
        exit;