FOF30\Download\Download::getFromURL PHP Method

getFromURL() public method

Important note about ranges: byte ranges start at 0. This means that the first 500 bytes of a file are from 0 to 499, NOT from 1 to 500. If you ask more bytes than there are in the file or a range which is invalid or does not exist this method will return false.
public getFromURL ( string $url, integer $from = null, integer $to = null ) : boolean | string
$url string The URL to download from
$from integer Byte range to start downloading from. Use null (default) for start of file.
$to integer Byte range to stop downloading. Use null to download the entire file ($from will be ignored!)
return boolean | string The downloaded data or false on failure
    public function getFromURL($url, $from = null, $to = null)
    {
        try {
            return $this->adapter->downloadAndReturn($url, $from, $to, $this->adapterOptions);
        } catch (DownloadError $e) {
            return false;
        }
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Check if the remote server environment matches our expectations.
  *
  * @throws  Exception
  */
 private function checkRemoteServerEnvironment()
 {
     $session = $this->container->session;
     $baseUrl = $session->get('transfer.url', '', 'akeeba');
     $baseUrl = rtrim($baseUrl, '/');
     $downloader = new Download($this->container);
     $rawData = $downloader->getFromURL($baseUrl . '/kickstart.php?task=serverinfo');
     if ($rawData == false) {
         // Cannot access Kickstart on the remote server
         throw new RuntimeException(JText::_('COM_AKEEBA_TRANSFER_ERR_CANNOTRUNKICKSTART'));
     }
     // Try to get the raw JSON data
     $pos = strpos($rawData, '###');
     if ($pos === false) {
         // Invalid AJAX data, no leading ###
         throw new RuntimeException(JText::_('COM_AKEEBA_TRANSFER_ERR_CANNOTRUNKICKSTART'));
     }
     // Remove the leading ###
     $rawData = substr($rawData, $pos + 3);
     $pos = strpos($rawData, '###');
     if ($pos === false) {
         // Invalid AJAX data, no trailing ###
         throw new RuntimeException(JText::_('COM_AKEEBA_TRANSFER_ERR_CANNOTRUNKICKSTART'));
     }
     // Remove the trailing ###
     $rawData = substr($rawData, 0, $pos);
     // Get the JSON response
     $data = @json_decode($rawData, true);
     if (empty($data)) {
         // Invalid AJAX data, can't decode this stuff
         throw new RuntimeException(JText::_('COM_AKEEBA_TRANSFER_ERR_CANNOTRUNKICKSTART'));
     }
     // Does the server have enough disk space?
     $freeSpace = $data['freeSpace'];
     $requiredSize = $this->getApproximateSpaceRequired();
     if ($requiredSize['size'] > $freeSpace) {
         $unit = array('b', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb');
         $freeSpaceString = @round($freeSpace / pow(1024, $i = floor(log($freeSpace, 1024))), 2) . ' ' . $unit[$i];
         throw new RuntimeException(JText::sprintf('COM_AKEEBA_TRANSFER_ERR_NOTENOUGHSPACE', $freeSpaceString, $requiredSize['string']));
     }
     // Can I write to remote files?
     $canWrite = $data['canWrite'];
     $canWriteTemp = $data['canWriteTemp'];
     if (!$canWrite && !$canWriteTemp) {
         throw new RuntimeException(JText::_('COM_AKEEBA_TRANSFER_ERR_CANNOTWRITEREMOTEFILES'));
     }
     if ($canWrite) {
         $session->set('transfer.targetPath', '', 'akeeba');
     } else {
         $session->set('transfer.targetPath', 'kicktemp', 'akeeba');
     }
     $session->set('transfer.remoteTimeLimit', $data['maxExecTime'], 'akeeba');
 }
All Usage Examples Of FOF30\Download\Download::getFromURL