Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Get the size of remote files #1186

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/Facebook/FileUpload/FacebookFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,36 @@ 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.
*
* @return int
*/
public function getSize()
{
if ($this->isRemoteFile($this->path)) {
return $this->getRemoteFileSize();
}

return filesize($this->path);
}

Expand Down