Download a file.

@param  string  $file
@param  string  $name
@return bool
185301
protected function downloadFile($file, $name = null)
    {
        if(file_exists($file) && is_file($file) && is_readable($file)) {
            $mime_type = mime_content_type($file);
            if(in_array($mime_type, ['image/gif', 'image/jpeg', 'image/png'])) {
                $exif_type = exif_imagetype($file);
                $img_ext = image_type_to_extension($exif_type);
                if($img_ext == '.jpeg') {
                    $img_ext = '.jpg';
                }
                switch($exif_type) {
                    case IMAGETYPE_JPEG:
                        $img = imagecreatefromjpeg($file);
                        imagejpeg( $img, NULL, 100 ); 
                        break;
                    case IMAGETYPE_GIF:
                        $img = imagecreatefromgif($file);
                        imagegif( $img ); 
                        break;
                    case IMAGETYPE_PNG:
                        $img = imagecreatefrompng($file);
                        imagepng( $img, NULL, 100 ); 
                        break;
                }
                if(!$img) {
                }
                else {
                    imagedestroy( $img );
                }
                $headers[] = "Content-Type: $mime_type";
                if($name !== null && trim($name) !== '') {
                    //download - without it image will not be downloaded just displayed on broswer
                    if( (strlen($name)-strlen($img_ext)) !== strpos($name, $img_ext) ) {
                        $name .= $img_ext;
                    }
                    $headers[] = "Content-Disposition: attachment; filename=$name";
                }
                self::$instance->app->headers = $headers;
            }
        }
    }
190898
public function downloadBill($file, array $args = array()) {
        return $this->getBill()->parameters($this->merge($args))->save($file);
    }
908994
public function upload($name)
    {
        // When $_FILES[$name]['name'] empty

        if ( empty($_FILES[$name]['name']) )
        {
            $this->error($this->errors['empty'], 0, true);

            return false;
        }

        $this->files = $_FILES[$name];

        // When the directory is not exist.
        if( !file_exists($this->savePath) )
        {
            $this->error($this->errors['not_exist'], 0, true);

            return false;
        }

        // When the directory is not written
        if( !is_writable($this->savePath) )
        {
            $this->error($this->errors['unwritable'], 0, true);

            return false;
        }

        return $this->moveFile();
    }
133601
public function isFile(String $name) : Bool
    {
        $file = Method::files($name);

        if( is_array($file) )
        {
            return (bool) $file[0];
        }

        return (bool) Method::files($name);
    }
880369
public function downloaded($name)
    {
        if ($this->local($name)) {
            return $this->filesystem->isDirectory(base_path("hooks/{$name}"))
                && $this->filesystem->exists(base_path("hooks/{$name}/composer.json"));
        }

        return $this->filesystem->isDirectory(base_path("vendor/{$name}"));
    }
201137
protected function downloadResponse($file, $name = null, array $headers = array())
	{
		$response = new BinaryFileResponse($file, 200, $headers, true, 'attachment');

		if ($name !== null) {
			return $response->setContentDisposition('attachment', $name, Str::ascii($name));
		}

		return $response;
	}
539816
public static function FromFile($Parent, $File, $Name = 'Configuration') {
      $LoadedFromCache = FALSE; $UseCache = FALSE;
      if ($Parent && $Parent->Caching()) {
         $FileKey = sprintf(Gdn_Configuration::CONFIG_FILE_CACHE_KEY, $File);
         if (Gdn::Cache()->Type() == Gdn_Cache::CACHE_TYPE_MEMORY && Gdn::Cache()->ActiveEnabled()) {
            $UseCache = TRUE;
            $CachedConfigData = Gdn::Cache()->Get($FileKey,array(
                Gdn_Cache::FEATURE_NOPREFIX => TRUE
            ));
            $LoadedFromCache = ($CachedConfigData !== Gdn_Cache::CACHEOP_FAILURE);
         }
      }
      
      // If we're not loading config from cache, check that the file exists
      if (!$LoadedFromCache && !file_exists($File))
         return FALSE;
         
      // Define the variable properly.
      $$Name = NULL;
      
      // If we're not loading config from cache, directly include the conf file
      if ($LoadedFromCache)
         $$Name = $CachedConfigData;
      
      if (is_null($$Name) || !is_array($$Name)) {
         $LoadedFromCache = FALSE;
         // Include the file.
         require($File);
      }
      
      // Make sure the config variable is here and is an array.
      if (!is_array($$Name))
         $$Name = array();
      
      // We're caching, using the cache, and this data was not loaded from cache.
      // Write it there now.
      if ($Parent && $Parent->Caching() && $UseCache && !$LoadedFromCache) {
         Gdn::Cache()->Store($FileKey, $$Name, array(
             Gdn_Cache::FEATURE_NOPREFIX => TRUE
         ));
      }
      
      return new Gdn_ConfigurationSource($Parent, 'file', $File, $Name, $$Name);
   }
883285
public function download($view, $data = [], $name = 'download')
    {
        $path = $this->processOutput($view, $data);

        return $this->responseDownload($path, $name);
    }
517069
public function hasFile(string $name) : bool
    {
        return $this->fileContentAreas->any(function (FileContentArea $contentArea) use ($name) {
            return $contentArea->name === $name;
        });
    }
875411
public function attachment($file, $name = null)
    {
        if (!is_null($name)) {
            $this->_attachments[] = ['name' => $key, 'file' => $value];
        } else {
            $this->_attachments[] = ['file' => $value];
        }

        return $this;
    }
636414
public function download($file, $name = null, array $headers = [], $disposition = 'attachment')
    {
        respondWith(response()->download($file, $name, $headers, $disposition ));
    }
845393
public function resolveFile($name)
    {
        $components = $this->parseResource($name);
        foreach ($components['dirs'] as $dir) {
            if (is_file($file = $dir . ($dir ? '/' : '') .  $components['file'])) {
                return $file;
            }
        }
        return false;
    }
1321224
public function file($name = null, $default = null)
    {
        $files = $this->request['files'];

        if (isset($name)) {
            return !empty($files[$name]['name']) ? $files[$name] : $default;
        }

        return $files;
    }
1307091
public function download($file, $filename = null, array $headers = [], $disposition = 'attachment')
    {
        $type = mime_content_type($file);

        if ($filename == null) {
            $filename = basename($file);
        }

        $this->addHeader('Content-Disposition', $disposition.'; filename='.$filename);

        $this->addHeader('Content-Type', $type);

        $this->addHeader('Content-Length', filesize($file));

        $this->addHeader('Content-Encoding', 'base64');

        foreach ($headers as $key => $value) {
            $this->addHeader($key, $value);
        }

        $this->download_filename = $file;

        $this->download = true;

        return $this->buildHttpResponse();
    }
1079770
public static function loadFromFile($name) {
        static $loader = null;
        if ($loader === null) {
            $loader = new ConfigurationLoader();
        }
        if (empty($name)) {
            return new Configuration('');
        } else {
            return $loader->loadConfig($name);
        }
    }
102412
public function saveAs($name)
    {
        if (!$this->getCommand()->getExecuted() && !$this->execute()) {
            return false;
        }
        $tmpFile = (string) $this->getTmpFile();
        if (!copy($tmpFile, $name)) {
            $this->_error = "Could not copy PDF from tmp location '$tmpFile' to '$name'";
            return false;
        }
        return true;
    }
1218279
private function cache(string $file, string $name)
	{
		$cache = str_replace($this->DS, '___', $name) . '@' . str_replace($this->DS, '___', $file);

		$compiled = $this->response(file_get_contents($file));

		file_put_contents($this->cacheDirectory . $this->DS . $cache, $compiled);
	}