Example #1
0
 /**
  * Download a file
  * 
  * @param string $url
  * @param \GO\Base\Fs\File $outputFile
  * @param array $params
  * @return boolean
  */
 public function downloadFile($url, \GO\Base\Fs\File $outputFile, $params = array())
 {
     $this->_lastDownloadUrl = $url;
     $this->_initRequest($url, $params);
     $fp = fopen($outputFile->path(), 'w');
     curl_setopt($this->_curl, CURLOPT_FILE, $fp);
     curl_setopt($this->_curl, CURLOPT_HEADERFUNCTION, array($this, 'readHeader'));
     $response = curl_exec($this->_curl);
     fclose($fp);
     if ($outputFile->size()) {
         return true;
     } else {
         return false;
     }
 }
Example #2
0
 /**
  * Output the right headers for outputting file data to a browser.
  * 
  * @param \GO\Base\Fs\File $file Use \GO\Base\Fs\MemoryFile for outputting variables
  * @param boolean $inline
  * @param boolean $cache Cache the file for one day in the browser.
  * @param array $extraHeaders  Key value array for extra headers
  */
 public static function outputDownloadHeaders(\GO\Base\Fs\File $file, $inline = true, $cache = false, $extraHeaders = array())
 {
     header('Content-Transfer-Encoding: binary');
     $disposition = $inline ? 'inline' : 'attachment';
     if ($cache) {
         header("Expires: " . date("D, j M Y G:i:s ", time() + 86400) . 'GMT');
         //expires in 1 day
         header('Cache-Control: cache');
         header('Pragma: cache');
     }
     if (Http::isInternetExplorer()) {
         header('Content-Type: application/download');
         header('Content-Disposition: ' . $disposition . '; filename="' . rawurlencode($file->name()) . '"');
         if (!$cache) {
             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
             header('Pragma: public');
         }
     } else {
         header('Content-Type: ' . $file->mimeType());
         header('Content-Disposition: ' . $disposition . '; filename="' . $file->name() . '"');
         if (!$cache) {
             header('Pragma: no-cache');
         }
     }
     if ($file->exists()) {
         if ($file->extension() != 'zip') {
             //Don't set content lenght for zip files because gzip of apache will corrupt the download. http://www.heath-whyte.info/david/computers/corrupted-zip-file-downloads-with-php
             header('Content-Length: ' . $file->size());
         }
         header("Last-Modified: " . gmdate("D, d M Y H:i:s", $file->mtime()) . " GMT");
         header("ETag: " . $file->md5Hash());
     }
     foreach ($extraHeaders as $header => $value) {
         header($header . ': ' . $value);
     }
 }
Example #3
0
 public function actionPasteUploadTemporary($filename, $filetype)
 {
     $type = explode('/', $filetype);
     $extension = $type[1];
     $_FILES['pastedFile']['name'] = $filename . '.' . $extension;
     $file = new GO\Base\Fs\File($_FILES['pastedFile']['tmp_name']);
     $file->move(GO::config()->getTempFolder(), $filename . '.' . $extension, true);
     $response = new \GO\Base\Data\JsonResponse(array('success' => true, 'data' => array('tmp_file' => $file->stripTempPath(), 'name' => $file->name(), 'size' => $file->size(), 'type' => $file->mimeType(), 'extension' => $file->extension(), 'human_size' => $file->humanSize(), 'from_file_storage' => false)));
     echo $response;
 }
Example #4
0
 /**
  * Add a filesystem file to this folder. The file will be moved to this folder
  * and added to the database.
  *
  * @param \GO\Base\Fs\File $file
  * @param boolean $appendNumberToNameIfExists Set if a number needs to be added to the name if the file already exists.
  * @return File
  */
 public function addFilesystemFile(\GO\Base\Fs\File $file, $appendNumberToNameIfExists = false)
 {
     if (!File::checkQuota($file->size())) {
         throw new \GO\Base\Exception\InsufficientDiskspace();
     }
     $file->move($this->fsFolder, false, false, $appendNumberToNameIfExists);
     $file->setDefaultPermissions();
     return $this->addFile($file->name());
 }