*/ class saProfileFotoResizeFile extends saUploadedFile { /** * Saves the uploaded file. * * This method can throw exceptions if there is a problem when saving the file. * * If you don't pass a file name, it will be generated by the generateFilename method. * This will only work if you have passed a path when initializing this instance. * * @param string $file The file path to save the file * @param int $fileMode The octal mode to use for the new file * @param bool $create Indicates that we should make the directory before moving the file * @param int $dirMode The octal mode to use when creating the directory * * @return string The filename without the $this->path prefix * * @throws Exception */ public function save($file = null, $fileMode = 0666, $create = true, $dirMode = 0777) { $file = parent::presave($file, $fileMode, $create, $dirMode); $pathinfo = pathinfo($file); $filename = $pathinfo['filename'].$this->getExtensionFromType(Profile::MIMETYPE); $big = $this->resize($filename, $dirMode, $fileMode, Profile::WIDTH, Profile::HEIGHT); $this->savedName = $big; return $filename; } protected function resize($filename, $dirMode, $fileMode, $width, $height) { if(!is_dir($this->path)) { mkdir($this->path, $dirMode, true); } $thumbnail = new sfThumbnail($width, $height, true, true, 95, 'sfGDAdapter'); $thumbnail->loadFile($this->getTempName()); $thumbnail->save($this->path.DIRECTORY_SEPARATOR.$filename, Profile::MIMETYPE); chmod($this->path.DIRECTORY_SEPARATOR.$filename, $fileMode); return $this->path.DIRECTORY_SEPARATOR.$filename; } }