Save remote file.

@param string $fileUrl  → remote file url
@param string $filePath → file path to save

@return bool
486504
private function saveRemoteFile($fileUrl, $filePath)
    {
        if (! $file = @file_get_contents($fileUrl)) {
            self::$errors[] = [
                'message' => 'Error to download file: ' . $fileUrl
            ];

            return false;
        }

        if (! @file_put_contents($filePath, $file)) {
            self::$errors[] = [
                'message' => 'Failed to save file to: ' . $filePath
            ];

            return false;
        }

        return true;
    }
497296
public static function save( $filePath, $value, $format = FALSE )
	{
		$writer	= new FS_File_JSON_Writer( $filePath );
		return $writer->write( $value, $format );
	}
1315812
public function put($localFile = null, $remoteFile = null, $mode = FTP_ASCII)
        {
            // attempt to upload file
            if(ftp_put(static::$_stream, $remoteFile, $localFile, $mode)) {
                // success
                return true;
            // upload failed
            } else {
                static::$error = "Failed to upload file \"{$localFile}\"";
                return false;
            }
        }
871534
public static void save(byte[] bytes,String filePath,String fileName) throws IOException {
        Path path = Paths.get(filePath, fileName);
        mkirDirs(path.getParent());
        String pathStr = path.toString();
        File file = new File(pathStr);
        write(bytes,file);
    }
226943
public function store(string $filePath = null, string $disk = null, string $writerType = null, $diskOptions = [])
    {
        $filePath = $filePath ?? $this->filePath ?? null;

        if (null === $filePath) {
            throw NoFilePathGivenException::export();
        }

        return $this->getExporter()->store(
            $this,
            $filePath,
            $disk ?? $this->disk ?? null,
            $writerType ?? $this->writerType ?? null,
            $diskOptions ?? $this->diskOptions ?? []
        );
    }
178954
protected function setFilePath($filePath)
	{
		if ( ! is_string($filePath))
		{
			throw new \InvalidArgumentException('File path must be a string type.');
		}
		
		if (preg_match('~^(\w+:)?//~', $filePath) || is_link($filePath))
		{
			throw new \InvalidArgumentException('File path must be a local path.');
		}
		
		$filePath = realpath($filePath);
		
		if ( ! is_file($filePath))
		{
			throw new TranscoderException('File path not found.');
		}
		
		$this->filePath = $filePath;
		
		return $this;
	}
181846
protected function download(string $filePath, ?string $filename = null): Response
    {
        return ResponseFactory::getInstance()->buildDownload($filePath, $filename);
    }
1115557
public static function createFromFilePath ($filePath)
    {
        if (!is_file($filePath))
        {
            throw new \InvalidArgumentException("File does not exist");
        }
        else if (!is_readable($filePath))
        {
            throw new \InvalidArgumentException("File to download is not readable.");
        }

        return new FileDownload(fopen($filePath, "rb"));
    }
14699
public function exists(string $filePath, string $mode = self::READ_BINARY) : bool
    {
        if (self::INPUT_STREAM === $filePath) {
            return true;
        }

        if (self::READ_BINARY === $mode && ! file_exists($filePath)) {
            throw new FileException('File not found.');
        }

        return true;
    }
1167498
protected function createFile($filePath, $contents)
    {
        $this->createDirectory(dirname($filePath));
        
        if (is_file($filePath)) {
            // if (!$this->opt('force')) {
            $this->output->setDecorated(true);
            $this->output->writeln(sprintf(
                "<comment>file exists  <cyan>%s</cyan></comment>",
                $this->prettyPath($filePath)
            ));
                // return;
            // } else {
                // $this->output->writeln(sprintf(
                    // "<comment>overwriten  <cyan>%s</cyan></comment>",
                    // $filePath
                // ));
            // }
        } else {
            $this->output->writeln(sprintf(
                "<info>create  <cyan>%s</cyan></info>",
                $this->prettyPath($filePath)
            ));
            file_put_contents($filePath, $contents);
        }
        
    }
984106
public static function getUrlPathFromFilePath($filePath, $relativeToRootUrl = false) {
		$dir = $filePath;
		$rootPath = ROOT_PATH;
		
		if (strpos($dir, ROOT_PATH) === 0) {
			$dirUrl = ROOT_URL.substr(ROOT_PATH, strlen(__DIR__)+1);
		} else {
			// The directory URL is below the ROOT_URL. Let's try to find it (not 100% success rate)
			$rootPaths = explode(DIRECTORY_SEPARATOR, trim($rootPath, DIRECTORY_SEPARATOR));
			$thisDirs = explode(DIRECTORY_SEPARATOR, trim($dir, DIRECTORY_SEPARATOR));
		
			for ($i=0; $i<count($rootPaths); $i++) {
				if ($rootPaths[$i] != $thisDirs[$i]) {
					break;
				}
			}
		
			$nbSkip = count($rootPaths) - $i;
			$urls = explode('/', trim(ROOT_URL, '/'));
		
			if ($nbSkip > count($urls)) {
				throw new Exception('The directory "'.$dir.'" is almost certainly out of reach from the web.');
			}
		
			$dirUrls = array();
			for ($j=0; $j < count($urls)- $nbSkip; $j++) {
				$dirUrls[] = $urls[$j];
			}
			for ($k = $i; $k<count($thisDirs); $k++) {
				$dirUrls[] = $thisDirs[$k];
			}
			$dirUrl = '/'.implode('/', $dirUrls);
			
			if ($relativeToRootUrl) {
				$dirUrl = ltrim(str_repeat('/..', count($urls)).$dirUrl, '/');
			}
		}
		return $dirUrl;
	}
712570
private function downloadFile(MDirectory $rootFolder, $filePath)
    {

        $file = $this->dropboxAccount->getDropboxApi()->getFile($filePath);
        $filePath = $rootFolder->getFolderName() . $filePath;
        $this->saveToFilesystem($filePath, $file);
    }
389145
public function store_destfile_from_path($filepath) {
        if ($record = $this->get_file_record()) {
            $fs = get_file_storage();
            $existing = $fs->get_file(
                $record['contextid'],
                $record['component'],
                $record['filearea'],
                $record['itemid'],
                $record['filepath'],
                $record['filename']
            );
            if ($existing) {
                $existing->delete();
            }
            $file = $fs->create_file_from_pathname($record, $filepath);

            $this->raw_set('destfileid', $file->get_id());
        }

        return $this;
    }
400663
public function createFile($filepath, $script, $rewrite = true)
    {
        $this->createDirectory(dirname($filepath));
        
        if (!file_exists($filepath) || $rewrite === true) {
            file_put_contents($filepath, $script);
        }
        
        return $this;
    }
255699
public function download($filePath)
    {
        $urlParts = parse_url($filePath);
        $rootDir = null;

        if (!is_null($this->rootDir)) {
            $rootDir = $this->rootDir;
        } else {
            $rootDir = CYGNITE_BASE.DS;
        }

        $filePath = $rootDir.str_replace('/', DS, str_replace('/'.ROOTDIR.'/', '', $urlParts['path']));

        if (is_null($this->filePath) && $filePath != '') {
            $this->filePath = $filePath;
        }

        $isSetFileType = $this->setMimeType($this->filePath);

        if ($isSetFileType) {
            $this->setHeaders();
        }
        //$this->filePath
    }
622323
public void ENsavehydfile( String filePath ) throws EpanetException {
        int err = epanet.ENsavehydfile(filePath);
        checkError(err);
    }
348804
public function uploadStoreLogo($filePath)
    {
        $filePath = realpath($filePath);
        if (!file_exists($filePath)) {
            return false;
        }
        $buffer = class_exists('\CURLFile') ? new \CURLFile($filePath) : '@' . $filePath;

        $result = $this->httpPost(self::WECHAT_MEDIA_IMG_UPLOAD_URL .
            'access_token=' . $this->getAccessToken() , [
            'buffer' => class_exists('\CURLFile') ? new \CURLFile($filePath) : '@' . $filePath
        ]);

        return isset($result['url']) ? $result['url'] : false;
    }