private function make()
 {
     // getimagesizefromstring() is implemented 5.4.0+ only.
     if (version_compare(PHP_VERSION, "5.4.0", "<")) {
         $path = "var/oldphp" . generateRandomChars(4, "0123456789");
         $overridefile = fopen($path, "w+b");
         fwrite($overridefile, $this->content);
         fclose($overridefile);
         list($width_orig, $height_orig) = getimagesize($path);
         unlink($path);
     } else {
         list($width_orig, $height_orig) = getimagesizefromstring($this->content);
     }
     $height = $this->width / $width_orig * $height_orig;
     $thumbnail = imagecreatetruecolor($this->width, $height);
     if ($thumbnail === FALSE) {
         throw new \Exception("GD was unable to create the thumbnail image.");
     }
     $image = imagecreatefromstring($this->content);
     imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $this->width, $height, $width_orig, $height_orig);
     switch ($this->type) {
         case "image/jpeg":
             imagejpeg($thumbnail, $this->filename);
             break;
         case "image/png":
             imagepng($thumbnail, $this->filename);
             break;
         case "image/gif":
             imagegif($thumbnail, $this->filename);
             break;
     }
     $handle = fopen($this->filename, "rb");
     $thumbstring = null;
     while (!feof($handle)) {
         $thumbstring .= fread($handle, self::CHUNK_SIZE);
     }
     $this->thumbnailString = $thumbstring;
     fclose($handle);
     imagedestroy($thumbnail);
     unlink($this->filename);
     return $thumbstring;
 }
 public function __construct($originalFilename, $type, $content)
 {
     $this->stordata = array('originalFilename' => $originalFilename, 'type' => $type, 'size' => (int) strlen($content), 'hash' => sha1($content), 'content' => $content, 'secretKey' => generateRandomChars(16));
 }
Exemple #3
0
function resetSpamTokens()
{
    $_SESSION['spam_key'] = generateRandomChars();
    $_SESSION['spam_val'] = generateRandomChars();
}
 echo "\t\t\t\t<th>Thumbnail</th>\n";
 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";
 public function build($name)
 {
     retry:
     try {
         $this->randomName = generateRandomChars(16);
         $this->pharObj = new \Phar($this->pharPath = PUBLIC_DATA_PATH . $name . "." . $this->randomName . ".phar");
     } catch (\UnexpectedValueException $e) {
         $err = true;
     }
     if (isset($err)) {
         goto retry;
     }
     $this->pharObj->setStub('<?php __HALT_COMPILER();');
     $this->pharObj->setSignatureAlgorithm(\Phar::SHA512);
     $this->pharObj->startBuffering();
     $this->pharObj->addFile($this->extractionPluginPath . "plugin.yml", "plugin.yml");
     $this->addRecr($this->extractionPluginPath . "src", "src");
     if (is_dir($this->extractionPluginPath . "resources")) {
         $this->addRecr($this->extractionPluginPath . "resources", "resources");
     }
     $this->pharObj->compressFiles(\Phar::GZ);
     $this->pharObj->stopBuffering();
 }