本文整理汇总了PHP中wcf\util\FileUtil类的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil类的具体用法?PHP FileUtil怎么用?PHP FileUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Calls all init functions of the WCF class.
*/
public function __construct()
{
// add autoload directory
self::$autoloadDirectories['wcf'] = WCF_DIR . 'lib/';
// define tmp directory
if (!defined('TMP_DIR')) {
define('TMP_DIR', FileUtil::getTempFolder());
}
// register additional autoloaders
require_once WCF_DIR . 'lib/system/api/phpline/phpline.phar';
require_once WCF_DIR . 'lib/system/api/zend/Loader/StandardAutoloader.php';
$zendLoader = new ZendLoader(array(ZendLoader::AUTOREGISTER_ZF => true));
$zendLoader->register();
$argv = new ArgvParser(array('packageID=i' => ''));
$argv->setOption(ArgvParser::CONFIG_FREEFORM_FLAGS, true);
$argv->parse();
define('PACKAGE_ID', $argv->packageID ?: 1);
// disable benchmark
define('ENABLE_BENCHMARK', 0);
// start initialization
$this->initDB();
$this->loadOptions();
$this->initSession();
$this->initLanguage();
$this->initTPL();
$this->initCoreObjects();
$this->initApplications();
// the destructor registered in core.functions.php will only call the destructor of the parent class
register_shutdown_function(array('wcf\\system\\CLIWCF', 'destruct'));
$this->initArgv();
$this->initPHPLine();
$this->initAuth();
$this->checkForUpdates();
$this->initCommands();
}
示例2: uninstall
/**
* @see wcf\system\package\plugin\IPackageInstallationPlugin::uninstall()
*/
public function uninstall() {
// create ACP-templates list
$templates = array();
// get ACP-templates from log
$sql = "SELECT *
FROM wcf".WCF_N."_acp_template
WHERE packageID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($this->installation->getPackageID()));
while ($row = $statement->fetchArray()) {
// store acp template with suffix (_$packageID)
$templates[] = 'acp/templates/'.$row['templateName'].'.tpl';
}
if (!empty($templates)) {
// delete template files
$packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR.$this->installation->getPackage()->packageDir));
$deleteEmptyDirectories = $this->installation->getPackage()->isApplication;
$this->installation->deleteFiles($packageDir, $templates, false, $deleteEmptyDirectories);
// delete log entries
parent::uninstall();
}
}
示例3: 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');
}
}
}
示例4: upload
/**
* Handles uploaded files.
*/
public function upload()
{
// save files
$files = $this->parameters['__files']->getFiles();
$file = $files[0];
try {
if (!$file->getValidationErrorType()) {
$data = array('userID' => WCF::getUser()->userID ?: null, 'filename' => $file->getFilename(), 'fileType' => $file->getMimeType(), 'fileHash' => sha1_file($file->getLocation()), 'filesize' => $file->getFilesize(), 'uploadTime' => TIME_NOW);
// save file
$upload = FileUploadEditor::create($data);
// move uploaded file
if (@copy($file->getLocation(), $upload->getLocation())) {
@unlink($file->getLocation());
// return result
return array('uploadID' => $upload->uploadID, 'filename' => $upload->filename, 'filesize' => $upload->filesize, 'formattedFilesize' => FileUtil::formatFilesize($upload->filesize));
} else {
// moving failed; delete file
$editor = new FileUploadEditor($upload);
$editor->delete();
throw new UserInputException('fileUpload', 'uploadFailed');
}
}
} catch (UserInputException $e) {
$file->setValidationErrorType($e->getType());
}
return array('errorType' => $file->getValidationErrorType());
}
示例5: save
/**
* @see \wcf\form\IForm::save()
*/
public function save()
{
parent::save();
$returnValues = $this->objectAction->getReturnValues();
// create folder for pictures of this category
FileUtil::makePath(NEWS_DIR . 'images/news/' . $returnValues['returnValues']->categoryID . '/');
}
示例6: __construct
/**
* Calls all init functions of the WCF and the WCFACP class.
*/
public function __construct() {
// add autoload directory
self::$autoloadDirectories['wcf'] = WCF_DIR . 'lib/';
// define tmp directory
if (!defined('TMP_DIR')) define('TMP_DIR', FileUtil::getTempFolder());
// start initialization
$this->initMagicQuotes();
$this->initDB();
$this->loadOptions();
$this->initPackage();
$this->initSession();
$this->initLanguage();
$this->initTPL();
$this->initCronjobs();
$this->initCoreObjects();
// prevent application loading during setup
if (PACKAGE_ID) {
$this->initApplications();
}
$this->initBlacklist();
$this->initAuth();
}
示例7: 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);
}
示例8: getData
/**
* @see \wcf\system\option\IOptionType::getData()
*/
public function getData(Option $option, $newValue)
{
$this->createUploadHandler($option);
if ($this->uploadHandlers[$option->optionName] === null) {
return '';
}
$files = $this->uploadHandlers[$option->optionName]->getFiles();
$file = reset($files);
// check if file has been uploaded
if (!$file->getFilename()) {
// if checkbox is checked, remove file
if ($newValue) {
@unlink($option->optionValue);
return '';
}
// use old value
return $option->optionValue;
} else {
if ($option->optionValue) {
// delete old file first
@unlink($option->optionValue);
}
}
// determine location the file will be stored at
$package = PackageCache::getInstance()->getPackage($option->packageID);
$fileLocation = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $package->packageDir)) . $option->filelocation . '.' . $file->getFileExtension();
// save file
move_uploaded_file($file->getLocation(), $fileLocation);
// return file location as the value to store in the database
return $fileLocation;
}
示例9: install
/**
* @see wcf\system\package\plugin\IPackageInstallationPlugin::install()
*/
public function install() {
parent::install();
// get installation path of package
$sql = "SELECT packageDir
FROM wcf".WCF_N."_package
WHERE packageID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($this->installation->getPackageID()));
$packageDir = $statement->fetchArray();
$packageDir = $packageDir['packageDir'];
// get relative path of script
$path = FileUtil::getRealPath(WCF_DIR.$packageDir);
// reset WCF cache
CacheHandler::getInstance()->flushAll();
// run script
$this->run($path.$this->instruction['value']);
// delete script
if (@unlink($path.$this->instruction['value'])) {
// delete file log entry
$sql = "DELETE FROM wcf".WCF_N."_package_installation_file_log
WHERE packageID = ?
AND filename = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array(
$this->installation->getPackageID(),
$this->instruction['value']
));
}
}
示例10: install
/**
* @see \wcf\system\package\plugin\IPackageInstallationPlugin::install()
*/
public function install()
{
parent::install();
$abbreviation = 'wcf';
$path = '';
if (isset($this->instruction['attributes']['application'])) {
$abbreviation = $this->instruction['attributes']['application'];
} else {
if ($this->installation->getPackage()->isApplication) {
$path = FileUtil::getRealPath(WCF_DIR . $this->installation->getPackage()->packageDir);
}
}
if (empty($path)) {
$dirConstant = strtoupper($abbreviation) . '_DIR';
if (!defined($dirConstant)) {
throw new SystemException("Cannot execute script-PIP, abbreviation '" . $abbreviation . "' is unknown");
}
$path = constant($dirConstant);
}
// reset WCF cache
CacheHandler::getInstance()->flushAll();
// run script
$this->run($path . $this->instruction['value']);
// delete script
if (@unlink($path . $this->instruction['value'])) {
// delete file log entry
$sql = "DELETE FROM\twcf" . WCF_N . "_package_installation_file_log\n\t\t\t\tWHERE\t\tpackageID = ?\n\t\t\t\t\t\tAND filename = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($this->installation->getPackageID(), $this->instruction['value']));
}
}
示例11: import
/**
* @see \wcf\system\importer\IImporter::import()
*/
public function import($oldID, array $data, array $additionalData = array())
{
// check file location
if (!@file_exists($additionalData['fileLocation'])) {
return 0;
}
// get image size
$imageData = @getimagesize($additionalData['fileLocation']);
if ($imageData === false) {
return 0;
}
$data['width'] = $imageData[0];
$data['height'] = $imageData[1];
// check min size
if ($data['width'] < 48 || $data['height'] < 48) {
return 0;
}
// check image type
if ($imageData[2] != IMAGETYPE_GIF && $imageData[2] != IMAGETYPE_JPEG && $imageData[2] != IMAGETYPE_PNG) {
return 0;
}
// get file hash
if (empty($data['fileHash'])) {
$data['fileHash'] = sha1_file($additionalData['fileLocation']);
}
// get user id
$data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
if (!$data['userID']) {
return 0;
}
// save avatar
$avatar = UserAvatarEditor::create($data);
// check avatar directory
// and create subdirectory if necessary
$dir = dirname($avatar->getLocation());
if (!@file_exists($dir)) {
FileUtil::makePath($dir, 0777);
}
// copy file
try {
if (!copy($additionalData['fileLocation'], $avatar->getLocation())) {
throw new SystemException();
}
// create thumbnails
$action = new UserAvatarAction(array($avatar), 'generateThumbnails');
$action->executeAction();
// update owner
$sql = "UPDATE\twcf" . WCF_N . "_user\n\t\t\t\tSET\tavatarID = ?\n\t\t\t\tWHERE\tuserID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($avatar->avatarID, $data['userID']));
return $avatar->avatarID;
} catch (SystemException $e) {
// copy failed; delete avatar
$editor = new UserAvatarEditor($avatar);
$editor->delete();
}
return 0;
}
示例12: rebuild
/**
* Assigns a list of applications to a group and computes cookie domain and path.
*/
public function rebuild() {
if (empty($this->objects)) {
$this->readObjects();
}
$sql = "UPDATE wcf".WCF_N."_application
SET cookieDomain = ?,
cookiePath = ?
WHERE packageID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
// calculate cookie path
$domains = array();
foreach ($this->objects as $application) {
if (!isset($domains[$application->domainName])) {
$domains[$application->domainName] = array();
}
$domains[$application->domainName][$application->packageID] = explode('/', FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash($application->domainPath)));
}
WCF::getDB()->beginTransaction();
foreach ($domains as $domainName => $data) {
$path = null;
foreach ($data as $domainPath) {
if ($path === null) {
$path = $domainPath;
}
else {
foreach ($path as $i => $part) {
if (!isset($domainPath[$i]) || $domainPath[$i] != $part) {
// remove all following elements including current one
foreach ($path as $j => $innerPart) {
if ($j >= $i) {
unset($path[$j]);
}
}
// skip to next domain
continue 2;
}
}
}
}
$path = FileUtil::addLeadingSlash(FileUtil::addTrailingSlash(implode('/', $path)));
foreach (array_keys($data) as $packageID) {
$statement->execute(array(
$domainName,
$path,
$packageID
));
}
}
WCF::getDB()->commitTransaction();
}
示例13: validate
/**
* @see \cms\system\content\type\IContentType::validate()
*/
public function validate($data)
{
if (!isset($data['video'])) {
throw new UserInputException('data[video]');
}
if (!FileUtil::isURL($data['video'])) {
throw new UserInputException('data[video]', 'notValid');
}
}
示例14: removeFiles
/**
* Removes files matching given pattern.
*
* @param string $pattern
*/
protected function removeFiles($pattern) {
$directory = FileUtil::unifyDirSeperator(WCF_DIR.'cache/');
$pattern = str_replace('*', '.*', str_replace('.', '\.', $pattern));
DirectoryUtil::getInstance($directory)->executeCallback(new Callback(function ($filename) {
if (!@touch($filename, 1)) {
@unlink($filename);
}
}), new Regex('^'.$directory.$pattern.'$', Regex::CASE_INSENSITIVE));
}
示例15: __construct
/**
* Creates a new UploadHandler object.
*
* @param array<mixed> $rawFileData
*/
protected function __construct(array $rawFileData)
{
if (is_array($rawFileData['name'])) {
// multiple uploads
for ($i = 0, $l = count($rawFileData['name']); $i < $l; $i++) {
$this->files[] = new UploadFile($rawFileData['name'][$i], $rawFileData['tmp_name'][$i], $rawFileData['size'][$i], $rawFileData['error'][$i], FileUtil::getMimeType($rawFileData['tmp_name'][$i]) ?: $rawFileData['type'][$i]);
}
} else {
$this->files[] = new UploadFile($rawFileData['name'], $rawFileData['tmp_name'], $rawFileData['size'], $rawFileData['error'], FileUtil::getMimeType($rawFileData['tmp_name']) ?: $rawFileData['type']);
}
}