downloads an external image to the server and stores it on the server

@param string  $file the URL to the original file
@return string the URL to the downloaded file
546936
public static function sideload_image( $file ) {
		$loc = self::get_sideloaded_file_loc($file);
		if ( file_exists($loc) ) {
			return URLHelper::file_system_to_url($loc);
		}
		// Download file to temp location
		if ( !function_exists('download_url') ) {
			require_once ABSPATH.'/wp-admin/includes/file.php';
		}
		$tmp = download_url($file);
		preg_match('/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches);
		$file_array = array();
		$file_array['name'] = basename($matches[0]);
		$file_array['tmp_name'] = $tmp;
		// If error storing temporarily, unlink
		if ( is_wp_error($tmp) ) {
			@unlink($file_array['tmp_name']);
			$file_array['tmp_name'] = '';
		}
		// do the validation and storage stuff
		$locinfo = pathinfo($loc);
		$file = wp_upload_bits($locinfo['basename'], null, file_get_contents($file_array['tmp_name']));
		return $file['url'];
	}
853364
protected function createFromUrl($file)
    {
        $ch = curl_init();

        curl_setopt_array($ch, [
            CURLOPT_URL => $file,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
            CURLOPT_FOLLOWLOCATION => 1,
        ]);

        $raw_file = curl_exec($ch);

        curl_close($ch);

        // Get the mime type of the file
        $size_info = getimagesizefromstring($raw_file);
        $mime = $size_info['mime'];

        // Create a file path for the file by storing it on disk.
        $file_path = @tempnam(sys_get_temp_dir(), 'STP');
        file_put_contents($file_path, $raw_file);

        // Get the original filename
        $name = strtok(pathinfo($file, PATHINFO_BASENAME), '?');

        // Append missing file extension
        if (empty(pathinfo($file, PATHINFO_EXTENSION))) {
            $name = $name . '.' . $this->getExtension($mime);
        }

        // Get the length of the file
        if (function_exists('mb_strlen')) {
            $size = mb_strlen($raw_file, '8bit');
        }
        else {
            $size = strlen($raw_file);
        }

        return new UploadedFile($file_path, $name, $mime, $size, 0);
    }
286618
public static function uploadsInternal($file = null)
    {
        return base_path(
            self::appendToPath(
                self::appendToPath(config('pxlcms.paths.base_internal'), config('pxlcms.paths.files')),
                $file
            )
        );
    }
610563
public static function image2Png($file)
    {
        try {
            if (is_file($file)) {
                return Image::open($file)->setCacheDir(dirname($file))->png();
            }
        } catch (Exception $e) {
        }
        return false;
    }
1271821
public static function get($file)
    {
        $type = str_replace('image/', NULL, Singleton::class('ZN\Helpers\Mime')->type($file));

        return $type === 'jpg' ? 'jpeg' : $type;
    }
826203
public function getUrl($file = '')
        {

            $version = $this->manager->getVersion();
            $pattern = $this->manager->getPattern();

            /** Search Params
             *  %f => $file
             *  %v => $version
             */

            $f = str_replace('%f', $file, $pattern);
            $v = str_replace('%v', $version, $f);

            return $this->getUrlString() . $v;
        }
796254
public function download(string $file, ?string $name = null, ?array $headers = [])
  {
    return Rest::download(self::url($file), $name, $headers);
  }
799298
public function download($file, $name = null, array $headers = [], $disposition = 'attachment')
    {
        $response = new BinaryFileResponse($file, 200, $headers, true, $disposition);

        if (! is_null($name)) {
            return $response->setContentDisposition($disposition, $name, $this->fallbackName($name));
        }

        return $response;
    }
356415
public function load(string $file)
    {
        $file = $this->sanitizeFileName($file);
        if (empty($this->loaded)
            && !empty($this->beforeFirstTimeLoadCallBack)
            && $this->isValid()
        ) {
            $callback = $this->beforeFirstTimeLoadCallBack;
            $callback($this);
            $this->beforeFirstTimeLoadCallBack = false;
        }

        $this->loaded[$file] = isset($this->loaded[$file])
            ? $this->loaded[$file]+1
            : 1;
        return RequireBinding::with(($this->getThemePath() . $file), $this);
    }
835538
public function handle($file)
    {
        if (!$mime = $this->getMimeForEmit($file->getExtension())) {
            return $file;
        }
        if (!$file_loc = $file->getLocation()) {
            return $file;
        }
        $file->setMime($mime);
        $file->setFound();
        $fp   = fopen($file_loc, 'r');
        $file->setResource($fp);

        return $file;
    }
1017421
public static function getFile( $file ) {
		$file = Storage::getFile( Route::DOCUMENT_ROOT() . 'app/config/' . $file . '.json' );
		$out  = Parser::json( $file );

		return $out;
	}
962770
public function make($file)
	{
		if ($file instanceof SymfonyUploadedFile) {
			return $this->createFromObject($file);
		}

		if (is_array($file)) {
			return $this->createFromArray($file);
		}

		if (substr($file, 0, 7) == "http://" || substr($file, 0, 8) == "https://") {
			return $this->createFromUrl($file);
		}

		return $this->createFromString($file);
	}
249409
protected static function load($file)
    {
        if (null !== static::DIRECTORY) {
            return file_get_contents(__DIR__.'/../data/'.static::DIRECTORY.'/'.$file.'.json');
        }

        return file_get_contents(__DIR__.'/../data/'.$file.'.json');
    }
813466
public function setImageFromFile($file)
    {
        if (preg_match('/\.([^\.]+)$/', $file, $match) === 1) {
            $this->setMimeType('image/' . $match[1]);
        }
        return $this->setImageFromBlob(file_get_contents($file));
    }
4336
public static function forceDownload($file)
    {
        if (isset($file)&&(file_exists($file))) {
           header("Content-length: ".filesize($file));  
           header('Content-Type: application/octet-stream');  
           header('Content-Disposition: attachment; filename="' . $file . '"'); 
           readfile($file);
        } else {
            echo "No file selected";
        }
    }
210937
public function loadFile($file, $url = null)
    {
        $this->_sourceUrl = $file;
        $str = $this->filesystem->fileGet($file);

        return $this->loadString($str, $url);
    }
569464
public function loadHtmlFile($file)
    {
        $this->saveLocale();

        if (!$this->protocol && !$this->baseHost && !$this->basePath) {
            list($this->protocol, $this->baseHost, $this->basePath) = Helpers::explode_url($file);
        }
        $protocol = strtolower($this->protocol);

        if ( !in_array($protocol, $this->allowedProtocols) ) {
            throw new Exception("Permission denied on $file. The communication protocol is not supported.");
        }

        if (!$this->options->isRemoteEnabled() && ($protocol != "" && $protocol !== "file://")) {
            throw new Exception("Remote file requested, but remote file download is disabled.");
        }

        if ($protocol == "" || $protocol === "file://") {
            $realfile = realpath($file);

            $chroot = realpath($this->options->getChroot());
            if ($chroot && strpos($realfile, $chroot) !== 0) {
                throw new Exception("Permission denied on $file. The file could not be found under the directory specified by Options::chroot.");
            }

            $ext = strtolower(pathinfo($realfile, PATHINFO_EXTENSION));
            if (!in_array($ext, $this->allowedLocalFileExtensions)) {
                throw new Exception("Permission denied on $file. This file extension is forbidden");
            }

            if (!$realfile) {
                throw new Exception("File '$file' not found.");
            }

            $file = $realfile;
        }

        list($contents, $http_response_header) = Helpers::getFileContent($file, $this->httpContext);
        $encoding = 'UTF-8';

        // See http://the-stickman.com/web-development/php/getting-http-response-headers-when-using-file_get_contents/
        if (isset($http_response_header)) {
            foreach ($http_response_header as $_header) {
                if (preg_match("@Content-Type:\s*[\w/]+;\s*?charset=([^\s]+)@i", $_header, $matches)) {
                    $encoding = strtoupper($matches[1]);
                    break;
                }
            }
        }

        $this->restoreLocale();

        $this->loadHtml($contents, $encoding);
    }