Example #1
0
 /**
  * Checks if a file path points to an external file
  */
 public function isExternal($file = '')
 {
     if (Validate::isExternal($file)) {
         return $file;
     }
     return false;
 }
Example #2
0
 /**
  * Get the domain name from current hostname
  */
 public static function getDomain($tld = true)
 {
     $hostname = self::getHost();
     $domain = preg_replace("/^(.*\\.)?([^.]*\\..*)\$/i", "\$2", $hostname);
     if (Validate::isIp($hostname) || Validate::isIpv6($hostname)) {
         return $hostname;
     }
     if ($tld !== true) {
         return preg_replace("/\\.[a-z]+\$/i", "", $domain);
     }
     return $domain;
 }
Example #3
0
 /**
  * Send file download response
  */
 public function download($path = '')
 {
     $this->flushHeaders();
     $this->flushContents();
     if (!empty($path)) {
         if (Validate::isUrl($path)) {
             $this->redirect($path);
         }
         if (is_file($path) !== true) {
             $this->setText(404, '404: The requested file could not be found.');
             $this->send();
         }
         $file = new File($path);
         $this->cacheExpire('-1 week');
         $this->setStatusCode(200);
         $this->setContentType($file->getMimeType());
         $this->setHeader('Content-Description', 'File Transfer', true);
         $this->setHeader('Content-Disposition', 'attachment; filename=' . $file->getSafeName() . ';', true);
         $this->setHeader('Content-Length', $file->getSize(), true);
         $this->setHeader('Content-Transfer-Encoding', 'binary', true);
         $this->sendHeaders();
         @readfile($file->getPath());
         exit;
     }
     throw new Exception('Tried to download a file without providing a valid file path.');
 }