From 8ae3f00a73579b409f171a0fd4ff41416c8e80fa Mon Sep 17 00:00:00 2001 From: Ali El Majdaoui Date: Thu, 23 Apr 2020 23:51:42 +0300 Subject: [PATCH] Get the size of remote files --- src/Facebook/FileUpload/FacebookFile.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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); }