Example #1
0
 public static function uploadFromUrl($url)
 {
     $fileStream = fopen($url, 'r');
     if ($fileStream === false) {
         return false;
     }
     $fileBasename = basename($url);
     $success = file_put_contents(File::getDefaultUploadBasePath() . DIRECTORY_SEPARATOR . $fileBasename, $fileStream);
     if (!$success) {
         throw new \RuntimeException(sprintf('File from url %1$s could not be received', $url));
     }
     return new static($fileBasename);
 }