__construct() public method

Constructs a new file from the given path.
public __construct ( string $path, boolean $checkPath = true )
$path string The path to the file
$checkPath boolean Whether to check the path or not
Example #1
0
 /**
  * {@inheritdoc}
  */
 public function __construct($path, $checkPath = true)
 {
     parent::__construct($path, $checkPath);
     if (false === strpos($this->getMimeType(), 'image')) {
         throw new \Exception(sprintf('Is not an image file. (%s)', $this->getMimeType()));
     }
 }
Example #2
0
 public function __construct($path)
 {
     try {
         parent::__construct($path, true);
     } catch (SFFileNotFoundException $e) {
         throw new FileNotFoundException(sprintf('File %s not found', $path));
     }
 }
 /**
  * @param string $path
  * @param bool   $checkPath
  *
  * @throws RuntimeException
  */
 public function __construct($path, $checkPath = true)
 {
     parent::__construct($path, $checkPath);
     if (0 !== strpos($this->getMimeType(), 'image/')) {
         $message = sprintf('File %s is not an image; Avalanche operates only on images', $path);
         throw new RuntimeException($message);
     }
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function __construct($handle)
 {
     if (!is_resource($handle)) {
         throw new \RuntimeException('handle is not a resource');
     }
     $this->resource = $handle;
     $meta = stream_get_meta_data($handle);
     parent::__construct($meta['uri']);
 }
Example #5
0
 /**
  * Accepts the information of the uploaded file as provided by the PHP global $_FILES.
  *
  * The file object is only created when the uploaded file is valid (i.e. when the
  * isValid() method returns true). Otherwise the only methods that could be called
  * on an UploadedFile instance are:
  *
  *   * getClientOriginalName,
  *   * getClientMimeType,
  *   * isValid,
  *   * getError.
  *
  * Calling any other method on an non-valid instance will cause an unpredictable result.
  *
  * @param string  $path         The full temporary path to the file
  * @param string  $originalName The original file name
  * @param string  $mimeType     The type of the file as provided by PHP
  * @param int     $size         The file size
  * @param int     $error        The error constant of the upload (one of PHP's UPLOAD_ERR_XXX constants)
  * @param bool    $test         Whether the test mode is active
  *
  * @throws FileException         If file_uploads is disabled
  * @throws FileNotFoundException If the file does not exist
  *
  * @api
  */
 public function __construct($path, $originalName, $mimeType = null, $size = null, $error = null, $test = false)
 {
     $this->originalName = $this->getName($originalName);
     $this->mimeType = $mimeType ?: 'application/octet-stream';
     $this->size = $size;
     $this->error = $error ?: UPLOAD_ERR_OK;
     $this->test = (bool) $test;
     parent::__construct($path, UPLOAD_ERR_OK === $this->error);
 }
Example #6
0
File: Image.php Project: hykz/Depot
 /**
  * {@inheritdoc}
  */
 public function __construct($path, $checkPath = true)
 {
     parent::__construct($path, $checkPath);
     if (false === strpos($this->getMimeType(), 'image')) {
         throw new \Exception(sprintf('Is not a image file. (%s)', $this->getMimeType()));
     }
     $format = $this->checkFormat($this->guessExtension());
     $generate = 'imagecreatefrom' . $format;
     $this->gd = new Gd();
     $this->gd->setResource($generate($this->getPathname()));
 }
Example #7
0
 /**
  * Constructs a new file from the given path.
  *
  * @param string|SplFileInfo $pathOrFile
  * @param string $original_name
  *
  */
 public function __construct($pathOrFile, $original_name)
 {
     $this->original_name = $original_name;
     if ($pathOrFile instanceof SplFileInfo) {
         parent::__construct($pathOrFile->getRealPath(), false);
     } elseif (is_string($pathOrFile)) {
         parent::__construct($pathOrFile, true);
     } else {
         throw new UnexpectedValueException('Input value must be string or SplFileInfo');
     }
 }
Example #8
0
 /**
  * Accepts the information of the uploaded file as provided by the PHP global $_FILES.
  *
  * @param string  $path         The full temporary path to the file
  * @param string  $originalName The original file name
  * @param string  $mimeType     The type of the file as provided by PHP
  * @param integer $size         The file size
  * @param integer $error        The error constant of the upload (one of PHP's UPLOAD_ERR_XXX constants)
  * @param Boolean $test         Whether the test mode is active
  *
  * @throws FileException         If file_uploads is disabled
  * @throws FileNotFoundException If the file does not exist
  */
 public function __construct($path, $originalName, $mimeType = null, $size = null, $error = null, $test = false)
 {
     if (!ini_get('file_uploads')) {
         throw new FileException(sprintf('Unable to create UploadedFile because "file_uploads" is disabled in your php.ini file (%s)', get_cfg_var('cfg_file_path')));
     }
     $this->originalName = basename($originalName);
     $this->mimeType = $mimeType ?: 'application/octet-stream';
     $this->size = $size;
     $this->error = $error ?: UPLOAD_ERR_OK;
     $this->test = (bool) $test;
     parent::__construct($path);
 }
Example #9
0
 public function __construct($base64Content, $originalName, $mimeType = null, $size = null)
 {
     $this->originalName = $this->getName($originalName);
     $this->mimeType = $mimeType ?: 'application/octet-stream';
     $this->size = $size;
     $filePath = tempnam(sys_get_temp_dir(), 'streetartlas_');
     $file = fopen($filePath, 'wb');
     $data = explode(',', $base64Content);
     fwrite($file, base64_decode($data[1]));
     $meta_data = stream_get_meta_data($file);
     $path = $meta_data['uri'];
     fclose($file);
     parent::__construct($path, true);
 }
Example #10
0
 public function __construct($realpath, $path)
 {
     $this->realpath = $realpath;
     parent::__construct($path, false);
 }
 /**
  * @param string $encoded
  * @param bool   $strict
  * @param bool   $checkPath
  */
 public function __construct($encoded, $strict = true, $checkPath = true)
 {
     parent::__construct($this->restoreToTemporary($encoded, $strict), $checkPath);
 }
Example #12
0
 /**
  * Constructs a new file from the given path.
  *
  * @param string $path      The path to the file
  * @param bool   $checkPath Whether to check the path or not
  *
  * @throws FileNotFoundException If the given path is not a file
  */
 public function __construct($path, $checkPath = true)
 {
     $this->getID3Info = new getID3();
     parent::__construct($path, $checkPath);
 }
 public function __construct($root_path, $web_path)
 {
     $this->root_path = $root_path;
     $this->web_path = $web_path;
     parent::__construct($root_path . $web_path);
 }