diff --git a/src/Facebook/FileUpload/FacebookFile.php b/src/Facebook/FileUpload/FacebookFile.php index 3c1536d43..3142ff028 100644 --- a/src/Facebook/FileUpload/FacebookFile.php +++ b/src/Facebook/FileUpload/FacebookFile.php @@ -135,6 +135,25 @@ public function getFilePath() return $this->path; } + /** + * Get the size of the remote file. + * + * @return float + */ + protected function getRemoteFileSize() + { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $this->path); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, true); + curl_setopt($ch, CURLOPT_NOBODY, true); + curl_exec($ch); + $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); + + return $size; + } + /** * Return the size of the file. * @@ -142,6 +161,10 @@ public function getFilePath() */ public function getSize() { + if ($this->isRemoteFile($this->path)) { + return $this->getRemoteFileSize(); + } + return filesize($this->path); }