示例#1
0
function getFlashParam()
{
    static $param;
    if (!isset($param)) {
        $param = isset($_GET[FLASH_KEY]) ? $_GET[FLASH_KEY] : Nette\Utils\Random::generate(4);
    }
    return $param;
}
示例#2
0
function getTempDir()
{
    return __DIR__ . '/../temp/' . Nette\Utils\Random::generate();
}
 public function process(\Nette\Application\UI\Form $form, $values)
 {
     $file = $values->file;
     if (!$file instanceof \Nette\Http\FileUpload) {
         throw new \Nette\FileNotFoundException('Nahraný soubor není typu Nette\\Http\\FileUpload. Pravděpodobně se nenahrál v pořádku.');
     }
     if (!$file->isOk()) {
         throw new \Nette\FileNotFoundException('Soubor byl poškozen:' . $file->error);
     }
     if ($this->isImage && $file->isImage() !== $this->isImage) {
         throw new \Nette\InvalidArgumentException('Soubor musí být obrázek');
     }
     if (is_array($this->allowType) && in_array($file->getContentType(), $this->allowType, TRUE)) {
         throw new \Nette\InvalidArgumentException('Soubor není povoleného typu');
     }
     $this->handleCheckDirectory();
     $targetPath = $this->wwwDir . DIRECTORY_SEPARATOR . $this->path;
     if ($this->randomFileName) {
         $SplitedName = \Nette\Utils\Strings::split($file->getSanitizedName(), '~\\.\\s*~');
         $suffix = array_pop($SplitedName);
         $random = new \Nette\Utils\Random();
         $randomName = $random->generate(48, '0-9a-zA-Z');
         while (is_file($targetPath . DIRECTORY_SEPARATOR . $randomName . '.' . $suffix)) {
             $randomName = $random->generate(48, '0-9a-zA-Z');
         }
         $name = $randomName . '.' . $suffix;
     } else {
         if ($this->rewriteExistingFiles) {
             $name = $file->getSanitizedName();
         } else {
             $SplitedName = \Nette\Utils\Strings::split($file->getSanitizedName(), '~\\.\\s*~');
             $suffix = array_pop($SplitedName);
             $counter = NULL;
             while (is_file($targetPath . DIRECTORY_SEPARATOR . implode('.', $SplitedName) . $counter . '.' . $suffix)) {
                 $counter++;
             }
             $name = implode('.', $SplitedName) . $counter . '.' . $suffix;
         }
     }
     if ($file->isImage()) {
         $image = $file->toImage();
         $width = $this->photo['width'];
         $height = $this->photo['height'];
         $flags = $this->photo['width'];
         if (!is_null($width) || !is_null($height)) {
             $image->resize($width, $height, $flags);
         }
         $image->save($targetPath . DIRECTORY_SEPARATOR . $name, $this->photo['quality'], $this->photo['type']);
     } else {
         $this->moveUploadedFile($file, $targetPath, $name);
     }
     if (!$this->randomFileName) {
         $fileName = implode('.', $SplitedName) . $counter;
     } else {
         $fileName = $randomName;
     }
     $this->onSuccess($this, $this->path, $fileName, $suffix);
 }