public static function createFromUploadedFile(UploadedFile $upload, $uploadPath, $filename = null)
    {
        if (!$upload->isValid()) {
            throw new UploadException(sprintf('An error occurred during file upload. Error code: %s', $upload->getError()));
        } elseif (($uploadPath = realpath($uploadPath . '/')) === false) {
            throw new UploadException('An error occurred during file upload. The specified upload path is invalid.');
        }

        if (!$filename) {
            $fullPath = sprintf(
                '%s%s%s.%s',
                rtrim($uploadPath, DIRECTORY_SEPARATOR),
                DIRECTORY_SEPARATOR,
                uniqid(),
                ($upload->getExtension() ?: ($upload->guessExtension() ?: 'file'))
            );
        } else {
            $fullPath = rtrim($uploadPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $filename;
        }

        $file = new self($fullPath, $upload->getClientOriginalName(), $upload->getMimeType(), $upload->getClientSize(), md5_file($upload->getRealPath()));
        $file->_uploadedFile = $upload;

        return $file;
    }
public static function createFromUploadedFile(UploadedFile $upload, $uploadPath, $filename = null)
    {
        if (!$upload->isValid()) {
            throw new UploadException(sprintf('An error occurred during file upload. Error code: %s', $upload->getError()));
        } elseif (($uploadPath = realpath($uploadPath . '/')) === false) {
            throw new UploadException('An error occurred during file upload. The specified upload path is invalid.');
        }

        if (!$filename) {
            $fullPath = sprintf(
                '%s%s%s.%s',
                rtrim($uploadPath, DIRECTORY_SEPARATOR),
                DIRECTORY_SEPARATOR,
                uniqid(),
                ($upload->getExtension() ?: ($upload->guessExtension() ?: 'file'))
            );
        } else {
            $fullPath = rtrim($uploadPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $filename;
        }

        $file = new self($fullPath, $upload->getClientOriginalName(), $upload->getMimeType(), $upload->getClientSize(), md5_file($upload->getRealPath()));
        $file->_uploadedFile = $upload;

        return $file;
    }
public static function createFromUploadedFile ( UploadedFile $ upload , $ uploadPath , $ filename = null ) { if ( ! $ upload -> isValid ( ) ) { throw new UploadException ( sprintf ( 'An error occurred during file upload. Error code: %s' , $ upload -> getError ( ) ) ) ; } elseif ( ( $ uploadPath = realpath ( $ uploadPath . '/' ) ) === false ) { throw new UploadException ( 'An error occurred during file upload. The specified upload path is invalid.' ) ; } if ( ! $ filename ) { $ fullPath = sprintf ( '%s%s%s.%s' , rtrim ( $ uploadPath , DIRECTORY_SEPARATOR ) , DIRECTORY_SEPARATOR , uniqid ( ) , ( $ upload -> getExtension ( ) ? : ( $ upload -> guessExtension ( ) ? : 'file' ) ) ) ; } else { $ fullPath = rtrim ( $ uploadPath , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . $ filename ; } $ file = new self ( $ fullPath , $ upload -> getClientOriginalName ( ) , $ upload -> getMimeType ( ) , $ upload -> getClientSize ( ) , md5_file ( $ upload -> getRealPath ( ) ) ) ; $ file -> _uploadedFile = $ upload ; return $ file ; }
Create From Uploaded File

@param \Symfony\Component\HttpFoundation\File\UploadedFile $upload
@param string                                              $uploadPath The directory to save the uploaded file to
@param string                                              $filename

@throws \Symfony\Component\HttpFoundation\File\Exception\UploadException
@return \Orkestra\Bundle\ApplicationBundle\Entity\File
Create From Uploaded File