/** loadRemoteFile(string $url,string $destination[,bool $overwrite_old = false]) * VISIBILITY: PUBLIC * USE: downloads a file from url and returns a new file object * */ public static function loadRemote($url, $destination, $overwrite_old = false) { $url = strtolower($url); if (instr($url, 'http://')) { $file = basename($url); if (!self::parsePath($destination, $file, $overwrite_old)) { return false; } if (basename($url) != $file) { //now we know the new name is ok but is the download name ok? if (is_file($destination . '/' . basename($url)) && !$overwrite_old) { $tmp = ''; do { $ext = '.tmp' . rand(0, 999); $tmp = $destination . '/' . basename($url) . $ext; } while (file_exists($tmp)); //ensure unique tmp $tmpfile = self::load($destination . '/' . basename($url)); if (!$tmpfile->mv($tmp)) { return false; } } } if (self::wgetFile($url, $destination)) { $fileobj = new File($destination . '/' . basename($url)); if (!empty($file)) { $fileobj->mv($destination . '/' . $file); } if (isset($tmpfile)) { $tmpfile->mv($destination . '/' . basename($url)); } return $fileobj; } } return false; }