Cheetah
FacebookFile.php
Go to the documentation of this file.
1 <?php
25 
27 
34 {
38  protected $path;
39 
43  private $maxLength;
44 
48  private $offset;
49 
53  protected $stream;
54 
64  public function __construct($filePath, $maxLength = -1, $offset = -1)
65  {
66  $this->path = $filePath;
67  $this->maxLength = $maxLength;
68  $this->offset = $offset;
69  $this->open();
70  }
71 
75  public function __destruct()
76  {
77  $this->close();
78  }
79 
85  public function open()
86  {
87  if (!$this->isRemoteFile($this->path) && !is_readable($this->path)) {
88  throw new FacebookSDKException('Failed to create FacebookFile entity. Unable to read resource: ' . $this->path . '.');
89  }
90 
91  $this->stream = fopen($this->path, 'r');
92 
93  if (!$this->stream) {
94  throw new FacebookSDKException('Failed to create FacebookFile entity. Unable to open resource: ' . $this->path . '.');
95  }
96  }
97 
101  public function close()
102  {
103  if (is_resource($this->stream)) {
104  fclose($this->stream);
105  }
106  }
107 
113  public function getContents()
114  {
115  return stream_get_contents($this->stream, $this->maxLength, $this->offset);
116  }
117 
123  public function getFileName()
124  {
125  return basename($this->path);
126  }
127 
133  public function getFilePath()
134  {
135  return $this->path;
136  }
137 
143  public function getSize()
144  {
145  return filesize($this->path);
146  }
147 
153  public function getMimetype()
154  {
155  return Mimetypes::getInstance()->fromFilename($this->path) ?: 'text/plain';
156  }
157 
165  protected function isRemoteFile($pathToFile)
166  {
167  return preg_match('/^(https?|ftp):\/\/.*/', $pathToFile) === 1;
168  }
169 }
Facebook\FileUpload\FacebookFile\$stream
$stream
Definition: FacebookFile.php:53
Facebook\FileUpload\Mimetypes\getInstance
static getInstance()
Definition: Mimetypes.php:954
Facebook\FileUpload\FacebookFile\getSize
getSize()
Definition: FacebookFile.php:143
Facebook\Exceptions\FacebookSDKException
Definition: FacebookSDKException.php:32
use
GNU LESSER GENERAL PUBLIC LICENSE February Free Software Inc Franklin Fifth MA USA Everyone is permitted to copy and distribute verbatim copies of this license but changing it is not allowed[This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it By the GNU General Public Licenses are intended to guarantee your freedom to share and change free software to make sure the software is free for all its users This the Lesser General Public applies to some specially designated software packages typically libraries of the Free Software Foundation and other authors who decide to use it You can use it but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular based on the explanations below When we speak of free we are referring to freedom of use
Definition: license.txt:27
php
Facebook\FileUpload
Definition: FacebookFile.php:24
Facebook\FileUpload\FacebookFile\getMimetype
getMimetype()
Definition: FacebookFile.php:153
Facebook\FileUpload\FacebookFile\isRemoteFile
isRemoteFile($pathToFile)
Definition: FacebookFile.php:165
Facebook\FileUpload\FacebookFile\getFileName
getFileName()
Definition: FacebookFile.php:123
Facebook\FileUpload\FacebookFile\getFilePath
getFilePath()
Definition: FacebookFile.php:133
Facebook\FileUpload\FacebookFile\open
open()
Definition: FacebookFile.php:85
Facebook\FileUpload\FacebookFile\__construct
__construct($filePath, $maxLength=-1, $offset=-1)
Definition: FacebookFile.php:64
Facebook\FileUpload\FacebookFile\__destruct
__destruct()
Definition: FacebookFile.php:75
Facebook\FileUpload\FacebookFile\close
close()
Definition: FacebookFile.php:101
Facebook\FileUpload\FacebookFile\getContents
getContents()
Definition: FacebookFile.php:113
Facebook\FileUpload\FacebookFile\$path
$path
Definition: FacebookFile.php:38
Facebook\FileUpload\FacebookFile
Definition: FacebookFile.php:34