本文整理汇总了PHP中eZFile类的典型用法代码示例。如果您正苦于以下问题:PHP eZFile类的具体用法?PHP eZFile怎么用?PHP eZFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了eZFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleFileDownload
function handleFileDownload($contentObject, $contentObjectAttribute, $type, $fileInfo)
{
$fileName = $fileInfo['filepath'];
$file = eZClusterFileHandler::instance($fileName);
if ($fileName != "" and $file->exists()) {
$fileSize = $file->size();
if (isset($_SERVER['HTTP_RANGE']) && preg_match("/^bytes=(\\d+)-(\\d+)?\$/", trim($_SERVER['HTTP_RANGE']), $matches)) {
$fileOffset = $matches[1];
$contentLength = isset($matches[2]) ? $matches[2] - $matches[1] + 1 : $fileSize - $matches[1];
} else {
$fileOffset = 0;
$contentLength = $fileSize;
}
// Figure out the time of last modification of the file right way to get the file mtime ... the
$fileModificationTime = $file->mtime();
// stop output buffering, and stop the session so that browsing can be continued while downloading
eZSession::stop();
ob_end_clean();
eZFile::downloadHeaders($fileName, self::dispositionType($fileInfo['mime_type']) === 'attachment', false, $fileOffset, $contentLength, $fileSize);
try {
$file->passthrough($fileOffset, $contentLength);
} catch (eZClusterFileHandlerNotFoundException $e) {
eZDebug::writeError($e->getMessage, __METHOD__);
header($_SERVER["SERVER_PROTOCOL"] . ' 500 Internal Server Error');
} catch (eZClusterFileHandlerGeneralException $e) {
eZDebug::writeError($e->getMessage, __METHOD__);
header($_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}
eZExecution::cleanExit();
}
return eZBinaryFileHandler::RESULT_UNAVAILABLE;
}
示例2: sendMail
function sendMail(eZMail $mail)
{
$ini = eZINI::instance();
$sendmailOptions = '';
$emailFrom = $mail->sender();
$emailSender = $emailFrom['email'];
if (!$emailSender || count($emailSender) <= 0) {
$emailSender = $ini->variable('MailSettings', 'EmailSender');
}
if (!$emailSender) {
$emailSender = $ini->variable('MailSettings', 'AdminEmail');
}
if (!eZMail::validate($emailSender)) {
$emailSender = false;
}
$isSafeMode = ini_get('safe_mode');
if ($isSafeMode and $emailSender and $mail->sender() == false) {
$mail->setSenderText($emailSender);
}
$filename = time() . '-' . mt_rand() . '.mail';
$data = preg_replace('/(\\r\\n|\\r|\\n)/', "\r\n", $mail->headerText() . "\n" . $mail->body());
$returnedValue = eZFile::create($filename, 'var/log/mail', $data);
if ($returnedValue === false) {
eZDebug::writeError('An error occurred writing the e-mail file in var/log/mail', __METHOD__);
}
return $returnedValue;
}
示例3: sendMail
function sendMail(ezcMail $mail)
{
$separator = "/";
$mail->appendExcludeHeaders(array('to', 'subject'));
$headers = rtrim($mail->generateHeaders());
// rtrim removes the linebreak at the end, mail doesn't want it.
if (count($mail->to) + count($mail->cc) + count($mail->bcc) < 1) {
throw new ezcMailTransportException('No recipient addresses found in message header.');
}
$additionalParameters = "";
if (isset($mail->returnPath)) {
$additionalParameters = "-f{$mail->returnPath->email}";
}
$sys = eZSys::instance();
$fname = time() . '-' . rand() . '.mail';
$qdir = eZSys::siteDir() . eZSys::varDirectory() . $separator . 'mailq';
$data = $headers . ezcMailTools::lineBreak();
$data .= ezcMailTools::lineBreak();
$data .= $mail->generateBody();
$data = preg_replace('/(\\r\\n|\\r|\\n)/', "\r\n", $data);
$success = eZFile::create($fname, $qdir, $data);
if ($success === false) {
throw new ezcMailTransportException('The email could not be sent by sendmail');
}
}
示例4: synchronise
public function synchronise(eZSolrBase $collection, $elevateXML, $params)
{
$uri_components = parse_url($collection->SearchServerURI);
// The extra variables are used to avoid PHP strict warnings using end() directly on the preg_split result
$pathElements = preg_split('/\\//', $uri_components['path']);
$collectionName = end($pathElements);
$filename = implode('__', array($uri_components['host'], $uri_components['port'], $collectionName, 'elevate.xml'));
return eZFile::create($filename, $params['base_dir'], $elevateXML);
}
示例5: testIssue16400
/**
* Regression test for issue 16400
* @link http://issues.ez.no/16400
* @return unknown_type
*/
public function testIssue16400()
{
$className = 'Media test class';
$classIdentifier = 'media_test_class';
$filePath = 'tests/tests/kernel/datatypes/ezmedia/ezmediatype_regression_issue16400.flv';
eZFile::create( $filePath );
$attributeName = 'Media';
$attributeIdentifier = 'media';
$attributeType = 'ezmedia';
//1. test method fetchByContentObjectID
$class = new ezpClass( $className, $classIdentifier, $className );
$class->add( $attributeName, $attributeIdentifier, $attributeType );
$attribute = $class->class->fetchAttributeByIdentifier( $attributeIdentifier );
$attribute->setAttribute( 'can_translate', 0 );
$class->store();
$object = new ezpObject( $classIdentifier, 2 );
$dataMap = $object->object->dataMap();
$fileAttribute = $dataMap[$attributeIdentifier];
$dataType = new eZMediaType();
$dataType->fromString( $fileAttribute, $filePath );
$fileAttribute->store();
$object->publish();
$object->refresh();
//verify fetchByContentObjectID
$mediaObject = eZMedia::fetch( $fileAttribute->attribute( 'id' ), 1 );
$medias = eZMedia::fetchByContentObjectID( $object->object->attribute( 'id' ) );
$this->assertEquals( $mediaObject->attribute( 'filename' ), $medias[0]->attribute( 'filename' ) );
$medias = eZMedia::fetchByContentObjectID( $object->object->attribute( 'id' ),
$fileAttribute->attribute( 'language_code' ) );
$this->assertEquals( $mediaObject->attribute( 'filename' ), $medias[0]->attribute( 'filename' ) );
//2. test issue
// create translation
$contentObject = $object->object;
$storedFileName = $mediaObject->attribute( 'filename' );
$version = $contentObject->createNewVersionIn( 'nor-NO',
$fileAttribute->attribute( 'language_code' ) );
$version->setAttribute( 'status', eZContentObjectVersion::STATUS_INTERNAL_DRAFT );
$version->store();
$version->removeThis();
$sys = eZSys::instance();
$dir = $sys->storageDirectory();
//verify the file is deleted
$storedFilePath = $dir . '/original/video/' . $storedFileName;
$file = eZClusterFileHandler::instance( $storedFilePath );
$this->assertTrue( $file->exists( $storedFilePath ) );
if ( $file->exists( $storedFilePath ) )
unlink( $storedFilePath );
}
示例6: __construct
private function __construct()
{
$ini_varnish = eZINI::instance('mugo_varnish.ini');
$this->debug = $ini_varnish->variable('VarnishSettings', 'DebugCurl') == 'enabled';
$this->varnishServers = $ini_varnish->variable('VarnishSettings', 'VarnishServers');
// override connection timeout
if ($ini_varnish->variable('VarnishSettings', 'ConnectionTimeout') > -1) {
$this->baseCurlOptions[CURLOPT_CONNECTTIMEOUT] = $ini_varnish->variable('VarnishSettings', 'ConnectionTimeout');
}
// make sure the log file exits
if (!file_exists(self::CURL_DEBUG_OUTPUT_FILE)) {
eZFile::create(self::CURL_DEBUG_OUTPUT_FILE);
}
}
示例7: checkMD5Sums
static function checkMD5Sums($file)
{
$lines = eZFile::splitLines($file);
$result = array();
if (is_array($lines)) {
foreach (array_keys($lines) as $key) {
$line =& $lines[$key];
if (strlen($line) > 34) {
$md5Key = substr($line, 0, 32);
$filename = substr($line, 34);
if (!file_exists($filename) || $md5Key != md5_file($filename)) {
$result[] = $filename;
}
}
}
}
return $result;
}
示例8: create
static function create($filename, $directory = false, $data = false, $atomic = false)
{
$filepath = $filename;
if ($directory) {
if (!file_exists($directory)) {
eZDir::mkdir($directory, false, true);
// eZDebugSetting::writeNotice( 'ezfile-create', "Created directory $directory", 'eZFile::create' );
}
$filepath = $directory . '/' . $filename;
}
// If atomic creation is needed we will use a temporary
// file when writing the data, then rename it to the correct path.
if ($atomic) {
$realpath = $filepath;
$dirname = dirname($filepath);
if (strlen($dirname) != 0) {
$dirname .= "/";
}
$filepath = $dirname . "ezfile-tmp." . md5($filepath . getmypid() . mt_rand());
}
$file = fopen($filepath, 'wb');
if ($file) {
// eZDebugSetting::writeNotice( 'ezfile-create', "Created file $filepath", 'eZFile::create' );
if ($data) {
if (is_resource($data)) {
// block-copy source $data to new $file in 1MB chunks
while (!feof($data)) {
fwrite($file, fread($data, 1048576));
}
fclose($data);
} else {
fwrite($file, $data);
}
}
fclose($file);
if ($atomic) {
// If the renaming process fails, delete the temporary file
eZFile::rename($filepath, $realpath, false, eZFile::CLEAN_ON_FAILURE);
}
return true;
}
// eZDebugSetting::writeNotice( 'ezfile-create', "Failed creating file $filepath", 'eZFile::create' );
return false;
}
示例9: trashStoredObjectAttribute
function trashStoredObjectAttribute($contentObjectAttribute, $version = null)
{
$contentObjectAttributeID = $contentObjectAttribute->attribute("id");
$imageHandler = $contentObjectAttribute->attribute('content');
$imageFiles = eZImageFile::fetchForContentObjectAttribute($contentObjectAttributeID);
foreach ($imageFiles as $imageFile) {
if ($imageFile == null) {
continue;
}
$existingFilepath = $imageFile;
// Check if there are any other records in ezimagefile that point to that filename.
$imageObjectsWithSameFileName = eZImageFile::fetchByFilepath(false, $existingFilepath);
$file = eZClusterFileHandler::instance($existingFilepath);
if ($file->exists() and count($imageObjectsWithSameFileName) <= 1) {
$orig_dir = dirname($existingFilepath) . '/trashed';
$fileName = basename($existingFilepath);
// create dest filename in the same manner as eZHTTPFile::store()
// grab file's suffix
$fileSuffix = eZFile::suffix($fileName);
// prepend dot
if ($fileSuffix) {
$fileSuffix = '.' . $fileSuffix;
}
// grab filename without suffix
$fileBaseName = basename($fileName, $fileSuffix);
// create dest filename
$newFileBaseName = md5($fileBaseName . microtime() . mt_rand());
$newFileName = $newFileBaseName . $fileSuffix;
$newFilepath = $orig_dir . '/' . $newFileName;
// rename the file, and update the database data
$imageHandler->updateAliasPath($orig_dir, $newFileBaseName);
if ($imageHandler->isStorageRequired()) {
$imageHandler->store($contentObjectAttribute);
$contentObjectAttribute->store();
}
}
}
}
示例10: downloadFile
/**
* Downloads file.
*
* Sets $this->ErrorMsg in case of an error.
*
* \private
* \param $url URL.
* \param $outDir Directory where to put downloaded file to.
* \param $forcedFileName Force saving downloaded file under this name.
* \return false on error, path to downloaded package otherwise.
*/
function downloadFile($url, $outDir, $forcedFileName = false)
{
$fileName = $outDir . "/" . ($forcedFileName ? $forcedFileName : basename($url));
eZDebug::writeNotice("Downloading file '{$fileName}' from {$url}");
// Create the out directory if not exists.
if (!file_exists($outDir)) {
eZDir::mkdir($outDir, false, true);
}
// First try CURL
if (extension_loaded('curl')) {
$ch = curl_init($url);
$fp = eZStepSiteTypes::fopen($fileName, 'wb');
if ($fp === false) {
$this->ErrorMsg = ezpI18n::tr('design/standard/setup/init', 'Cannot write to file') . ': ' . $this->FileOpenErrorMsg;
return false;
}
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
// Get proxy
$ini = eZINI::instance();
$proxy = $ini->hasVariable('ProxySettings', 'ProxyServer') ? $ini->variable('ProxySettings', 'ProxyServer') : false;
if ($proxy) {
curl_setopt($ch, CURLOPT_PROXY, $proxy);
$userName = $ini->hasVariable('ProxySettings', 'User') ? $ini->variable('ProxySettings', 'User') : false;
$password = $ini->hasVariable('ProxySettings', 'Password') ? $ini->variable('ProxySettings', 'Password') : false;
if ($userName) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "{$userName}:{$password}");
}
}
if (!curl_exec($ch)) {
$this->ErrorMsg = curl_error($ch);
return false;
}
curl_close($ch);
fclose($fp);
} else {
$parsedUrl = parse_url($url);
$checkIP = isset($parsedUrl['host']) ? ip2long(gethostbyname($parsedUrl['host'])) : false;
if ($checkIP === false) {
return false;
}
// If we don't have CURL installed we used standard fopen urlwrappers
// Note: Could be blocked by not allowing remote calls.
if (!copy($url, $fileName)) {
$buf = eZHTTPTool::sendHTTPRequest($url, 80, false, 'eZ Publish', false);
$header = false;
$body = false;
if (eZHTTPTool::parseHTTPResponse($buf, $header, $body)) {
eZFile::create($fileName, false, $body);
} else {
$this->ErrorMsg = ezpI18n::tr('design/standard/setup/init', 'Failed to copy %url to local file %filename', null, array("%url" => $url, "%filename" => $fileName));
return false;
}
}
}
return $fileName;
}
示例11: saveCache
/**
* Stores the content of the INI object to the cache file \a $cachedFile.
*
* @param string $cachedDir Cache dir, usually "var/cache/ini/"
* @param string $cachedFile Name of cache file as returned by cacheFileName()
* @param array $data Configuration data as an associative array structure
* @param array $inputFiles List of input files used as basis for cache (for use in load cache to check mtime)
* @param string $iniFile Ini file path string returned by findInputFiles() for main ini file
* @return bool
*/
protected function saveCache($cachedDir, $cachedFile, array $data, array $inputFiles, $iniFile)
{
if (!file_exists($cachedDir)) {
if (!eZDir::mkdir($cachedDir, 0777, true)) {
eZDebug::writeError("Couldn't create cache directory {$cachedDir}, perhaps wrong permissions", __METHOD__);
return false;
}
}
// Save the data to a temp cached file
$tmpCacheFile = $cachedFile . '_' . substr(md5(mt_rand()), 0, 8);
$fp = @fopen($tmpCacheFile, "w");
if ($fp === false) {
eZDebug::writeError("Couldn't create cache file '{$cachedFile}', perhaps wrong permissions?", __METHOD__);
return false;
}
// Write cache data as a php structure with some meta information for use while reading cache
fwrite($fp, "<?php\n// This is a auto generated ini cache file, time created:" . date(DATE_RFC822) . "\n");
fwrite($fp, "\$data = array(\n");
fwrite($fp, "'rev' => " . eZINI::CONFIG_CACHE_REV . ",\n");
fwrite($fp, "'created' => '" . date('c') . "',\n");
if ($this->Codec) {
fwrite($fp, "'charset' => \"" . $this->Codec->RequestedOutputCharsetCode . "\",\n");
} else {
fwrite($fp, "'charset' => \"{$this->Charset}\",\n");
}
fwrite($fp, "'files' => " . preg_replace("@\n[\\s]+@", '', var_export($inputFiles, true)) . ",\n");
fwrite($fp, "'file' => '{$iniFile}',\n");
fwrite($fp, "'val' => " . preg_replace("@\n[\\s]+@", '', var_export($data, true)) . ");");
fwrite($fp, "\n?>");
fclose($fp);
// Rename cache temp file to final desitination and set permissions
eZFile::rename($tmpCacheFile, $cachedFile);
chmod($cachedFile, self::$filePermission);
if (eZINI::isDebugEnabled()) {
eZDebug::writeNotice("Wrote cache file '{$cachedFile}'", __METHOD__);
}
return true;
}
示例12: storeCache
/**
* Stores the data in $fileData to the remote and local file and commits the
* transaction.
*
* The parameter $fileData must contain the same as information as the
* $generateCallback returns as explained in processCache().
* @note This method is just a continuation of the code in processCache()
* and is not meant to be called alone since it relies on specific
* state in the database.
*/
public function storeCache($fileData)
{
$scope = false;
$datatype = false;
$binaryData = null;
$fileContent = null;
$store = true;
$storeCache = false;
if (is_array($fileData)) {
if (isset($fileData['scope'])) {
$scope = $fileData['scope'];
}
if (isset($fileData['datatype'])) {
$datatype = $fileData['datatype'];
}
if (isset($fileData['content'])) {
$fileContent = $fileData['content'];
}
if (isset($fileData['binarydata'])) {
$binaryData = $fileData['binarydata'];
}
if (isset($fileData['store'])) {
$store = $fileData['store'];
}
} else {
$binaryData = $fileData;
}
// This checks if we entered timeout and got our generating file stolen
// If this happens, we don't store our cache
if ($store and $this->checkCacheGenerationTimeout()) {
$storeCache = true;
}
$result = null;
if ($binaryData === null && $fileContent === null) {
eZDebug::writeError("Write callback need to set the 'content' or 'binarydata' entry for '{$this->filePath}'", __METHOD__);
$this->abortCacheGeneration();
return null;
}
if ($binaryData === null) {
$binaryData = "<" . "?php\n\treturn " . var_export($fileContent, true) . ";\n?" . ">\n";
}
if ($fileContent === null) {
$result = $binaryData;
} else {
$result = $fileContent;
}
if (!$this->filePath) {
return $result;
}
// no store advice from cache generation timeout or disabled viewcache,
// we just return the result
if (!$storeCache) {
eZDebugSetting::writeDebug('kernel-clustering', "Not storing this cache", __METHOD__);
$this->abortCacheGeneration();
return $result;
}
// stale cache handling: we just return the result, no lock has been set
if ($this->useStaleCache) {
eZDebugSetting::writeDebug('kernel-clustering', "Stalecache mode enabled for this cache", "dfs::storeCache( {$this->filePath} )");
// we write the generated cache to disk if it does not exist yet,
// to speed up the next uncached operation
// This file will be overwritten by the real file
clearstatcache();
if (!file_exists($this->filePath)) {
eZDebugSetting::writeDebug('kernel-clustering', "Writing stale file content to local file {$this->filePath}", __METHOD__);
eZFile::create(basename($this->filePath), dirname($this->filePath), $binaryData, true);
}
return $result;
}
// Check if we are allowed to store the data, if not just return the result
if (!$store) {
$this->abortCacheGeneration();
return $result;
}
// Distinguish bool from eZClusterFileFailure, and call abortCacheGeneration()
$storeContentsResult = $this->storeContents($binaryData, $scope, $datatype, $storeLocally = false);
// Cache was stored, we end cache generation
if ($storeContentsResult === true) {
$this->endCacheGeneration();
} else {
if ($storeContentsResult instanceof eZMySQLBackendError) {
$this->abortCacheGeneration();
}
}
// We don't do anything if false (not stored for known reasons) has been returned
return $result;
}
示例13: create
static function create($filename, $directory = false, $data = false, $atomic = false)
{
$filepath = $filename;
if ($directory) {
if (!file_exists($directory)) {
eZDir::mkdir($directory, false, true);
// eZDebugSetting::writeNotice( 'ezfile-create', "Created directory $directory", 'eZFile::create' );
}
$filepath = $directory . '/' . $filename;
}
// If atomic creation is needed we will use a temporary
// file when writing the data, then rename it to the correct path.
if ($atomic) {
$realpath = $filepath;
$dirname = dirname($filepath);
if (strlen($dirname) != 0) {
$dirname .= "/";
}
$filepath = $dirname . "ezfile-tmp." . md5($filepath . getmypid() . mt_rand());
}
$file = fopen($filepath, 'wb');
if ($file) {
// eZDebugSetting::writeNotice( 'ezfile-create', "Created file $filepath", 'eZFile::create' );
if ($data) {
fwrite($file, $data);
}
fclose($file);
if ($atomic) {
eZFile::rename($filepath, $realpath);
}
return true;
}
// eZDebugSetting::writeNotice( 'ezfile-create', "Failed creating file $filepath", 'eZFile::create' );
return false;
}
示例14: eZSetupPrvtAreDirAndFilesWritable
function eZSetupPrvtAreDirAndFilesWritable($dir)
{
if (!eZDir::isWriteable($dir)) {
return FALSE;
}
// Check if all files within a given directory are writeable
$files = eZDir::findSubitems($dir, 'f');
// find only files, skip dirs and symlinks
$fileSeparator = eZSys::fileSeparator();
foreach ($files as $file) {
if (!eZFile::isWriteable($dir . $fileSeparator . $file)) {
return FALSE;
}
}
return TRUE;
}
示例15: close
function close()
{
if ($this->ClusteringEnabled) {
$this->ClusterHandler = null;
return;
}
if ($this->FileResource) {
fclose($this->FileResource);
if ($this->isAtomic) {
eZFile::rename($this->tmpFilename, $this->requestedFilename);
}
$this->FileResource = false;
}
}