本文整理汇总了PHP中wcf\util\FileUtil::downloadFileFromHttp方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil::downloadFileFromHttp方法的具体用法?PHP FileUtil::downloadFileFromHttp怎么用?PHP FileUtil::downloadFileFromHttp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wcf\util\FileUtil
的用法示例。
在下文中一共展示了FileUtil::downloadFileFromHttp方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* @see \wcf\form\IForm::validate()
*/
public function validate()
{
parent::validate();
// check if file is uploaded or linked
if (!empty($this->file['tmp_name'])) {
$this->backup = $this->file['tmp_name'];
} else {
if ($this->fileLink != '') {
//check if file is external url
if (FileUtil::isURL($this->fileLink)) {
try {
//download file
$this->backup = FileUtil::downloadFileFromHttp($this->fileLink, 'cms_backup');
} catch (SystemException $e) {
//download failed
throw new UserInputException('fileLink', 'downloadFailed');
}
} else {
//file not found
if (!file_exists($this->fileLink)) {
throw new UserInputException('fileLink', 'notFound');
} else {
$this->backup = $this->fileLink;
}
}
} else {
throw new UserInputException('file', 'empty');
}
}
}
示例2: execute
/**
* @see wcf\system\ICronjob::execute()
*/
public function execute(Cronjob $cronjob)
{
$filename = FileUtil::downloadFileFromHttp('http://www.woltlab.com/spiderlist/spiderlist.xml', 'spiders');
$xml = new XML();
$xml->load($filename);
$xpath = $xml->xpath();
// fetch spiders
$spiders = $xpath->query('/spiderlist/spider');
if (count($spiders)) {
// delete old entries
$sql = "DELETE FROM wcf" . WCF_N . "_spider";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute();
$statementParameters = array();
foreach ($spiders as $spider) {
$identifier = StringUtil::toLowerCase($spider->getAttribute('ident'));
$name = $xpath->query('name', $spider)->item(0);
$info = $xpath->query('info', $spider)->item(0);
$statementParameters[$identifier] = array('spiderIdentifier' => $identifier, 'spiderName' => $name->nodeValue, 'spiderURL' => $info ? $info->nodeValue : '');
}
if (!empty($statementParameters)) {
$sql = "INSERT INTO\twcf" . WCF_N . "_spider\n\t\t\t\t\t\t\t(spiderIdentifier, spiderName, spiderURL)\n\t\t\t\t\tVALUES\t\t(?, ?, ?)";
$statement = WCF::getDB()->prepareStatement($sql);
foreach ($statementParameters as $parameters) {
$statement->execute(array($parameters['spiderIdentifier'], $parameters['spiderName'], $parameters['spiderURL']));
}
}
// clear spider cache
CacheHandler::getInstance()->clear(WCF_DIR . 'cache', 'cache.spiders.php');
}
// delete tmp file
@unlink($filename);
}
示例3: execute
/**
* @see \wcf\system\ICronjob::execute()
*/
public function execute(Cronjob $cronjob)
{
$filename = FileUtil::downloadFileFromHttp('http://assets.woltlab.com/spiderlist/typhoon/list.xml', 'spiders');
$xml = new XML();
$xml->load($filename);
$xpath = $xml->xpath();
// fetch spiders
$spiders = $xpath->query('/ns:data/ns:spider');
if (!empty($spiders)) {
$existingSpiders = SpiderCacheBuilder::getInstance()->getData();
$statementParameters = array();
foreach ($spiders as $spider) {
$identifier = mb_strtolower($spider->getAttribute('ident'));
$name = $xpath->query('ns:name', $spider)->item(0);
$info = $xpath->query('ns:url', $spider)->item(0);
$statementParameters[$identifier] = array('spiderIdentifier' => $identifier, 'spiderName' => $name->nodeValue, 'spiderURL' => $info ? $info->nodeValue : '');
}
if (!empty($statementParameters)) {
$sql = "INSERT INTO\t\t\twcf" . WCF_N . "_spider\n\t\t\t\t\t\t\t\t\t(spiderIdentifier, spiderName, spiderURL)\n\t\t\t\t\tVALUES\t\t\t\t(?, ?, ?)\n\t\t\t\t\tON DUPLICATE KEY UPDATE\t\tspiderName = VALUES(spiderName),\n\t\t\t\t\t\t\t\t\tspiderURL = VALUES(spiderURL)";
$statement = WCF::getDB()->prepareStatement($sql);
WCF::getDB()->beginTransaction();
foreach ($statementParameters as $parameters) {
$statement->execute(array($parameters['spiderIdentifier'], $parameters['spiderName'], $parameters['spiderURL']));
}
WCF::getDB()->commitTransaction();
}
// delete obsolete entries
$sql = "DELETE FROM wcf" . WCF_N . "_spider WHERE spiderIdentifier = ?";
$statement = WCF::getDB()->prepareStatement($sql);
foreach ($existingSpiders as $spider) {
if (!isset($statementParameters[$spider->spiderIdentifier])) {
$statement->execute(array($spider->spiderIdentifier));
}
}
// clear spider cache
SpiderCacheBuilder::getInstance()->reset();
}
// delete tmp file
@unlink($filename);
}
示例4: test
/**
* Checks a given email address for gravatar support.
*
* @param string $email
* @return boolean
*/
public static function test($email)
{
$gravatarURL = sprintf(self::GRAVATAR_BASE, md5(mb_strtolower($email)), 80, GRAVATAR_DEFAULT_TYPE);
try {
$tmpFile = FileUtil::downloadFileFromHttp($gravatarURL, 'gravatar');
@unlink($tmpFile);
return true;
} catch (SystemException $e) {
return false;
}
}
示例5: downloadArchive
/**
* Downloads the package archive.
*
* @return string path to the dowloaded file
*/
public function downloadArchive() {
$prefix = 'package';
// file transfer via hypertext transfer protocol.
$this->archive = FileUtil::downloadFileFromHttp($this->archive, $prefix);
// unzip tar
$this->archive = self::unzipPackageArchive($this->archive);
return $this->archive;
}