本文整理汇总了PHP中eZHTTPFile::canFetch方法的典型用法代码示例。如果您正苦于以下问题:PHP eZHTTPFile::canFetch方法的具体用法?PHP eZHTTPFile::canFetch怎么用?PHP eZHTTPFile::canFetch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZHTTPFile
的用法示例。
在下文中一共展示了eZHTTPFile::canFetch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
/**
* @copyright Copyright (C) 1999-2013 eZ Systems AS. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
* @version 2013.11
* @package kernel
*/
$module = $Params['Module'];
if (!eZPackage::canUsePolicyFunction('import')) {
return $module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel');
}
$package = false;
$installElements = false;
$errorList = array();
if ($module->isCurrentAction('UploadPackage')) {
if (eZHTTPFile::canFetch('PackageBinaryFile')) {
$file = eZHTTPFile::fetch('PackageBinaryFile');
if ($file) {
$packageFilename = $file->attribute('filename');
$package = eZPackage::import($packageFilename, $packageName);
if ($package instanceof eZPackage) {
if ($package->attribute('install_type') != 'install' or !$package->attribute('can_install')) {
return $module->redirectToView('view', array('full', $package->attribute('name')));
} else {
if ($package->attribute('install_type') == 'install') {
return $module->redirectToView('install', array($package->attribute('name')));
}
}
} else {
if ($package == eZPackage::STATUS_ALREADY_EXISTS) {
$errorList[] = array('description' => ezpI18n::tr('kernel/package', 'Package %packagename already exists, cannot import the package', false, array('%packagename' => $packageName)));
示例2: fetchObjectAttributeHTTPInput
/**
* Fetch object attribute http input, override the ezDataType method
* This method is triggered when submiting a http form which includes Image class
* Image is stored into file system every time there is a file input and validation result is valid.
* @param $http http object
* @param $base
* @param $contentObjectAttribute : the content object attribute being handled
* @return true if content object is not null, false if content object is null
*/
function fetchObjectAttributeHTTPInput($http, $base, $contentObjectAttribute)
{
$result = false;
$imageAltText = false;
$hasImageAltText = false;
if ($http->hasPostVariable($base . "_data_imagealttext_" . $contentObjectAttribute->attribute("id"))) {
$imageAltText = $http->postVariable($base . "_data_imagealttext_" . $contentObjectAttribute->attribute("id"));
$hasImageAltText = true;
}
$content = $contentObjectAttribute->attribute('content');
$httpFileName = $base . "_data_imagename_" . $contentObjectAttribute->attribute("id");
if (eZHTTPFile::canFetch($httpFileName)) {
$httpFile = eZHTTPFile::fetch($httpFileName);
if ($httpFile) {
if ($content) {
$content->setHTTPFile($httpFile);
$result = true;
}
}
}
if ($content) {
if ($hasImageAltText) {
$content->setAttribute('alternative_text', $imageAltText);
}
$result = true;
}
return $result;
}
示例3: uploadPackage
/**
* Upload local package.
*
* \private
*/
function uploadPackage()
{
if (!eZHTTPFile::canFetch('PackageBinaryFile')) {
$this->ErrorMsg = ezpI18n::tr('design/standard/setup/init', 'No package selected for upload') . '.';
return;
}
$file = eZHTTPFile::fetch('PackageBinaryFile');
if (!$file) {
$this->ErrorMsg = ezpI18n::tr('design/standard/setup/init', 'Failed fetching upload package file');
return;
}
$packageFilename = $file->attribute('filename');
$packageName = $file->attribute('original_filename');
if (preg_match("#^(.+)-[0-9](\\.[0-9]+)-[0-9].ezpkg\$#", $packageName, $matches)) {
$packageName = $matches[1];
}
$packageName = preg_replace(array("#[^a-zA-Z0-9]+#", "#_+#", "#(^_)|(_\$)#"), array('_', '_', ''), $packageName);
$package = eZPackage::import($packageFilename, $packageName, false);
if (is_object($package)) {
// package successfully imported
return;
} elseif ($package == eZPackage::STATUS_ALREADY_EXISTS) {
eZDebug::writeWarning("Package '{$packageName}' already exists.");
} else {
$this->ErrorMsg = ezpI18n::tr('design/standard/setup/init', 'Uploaded file is not an eZ Publish package');
}
}
示例4: validateImageFiles
function validateImageFiles( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
{
// If we don't have an image we continue as normal
if ( !eZHTTPFile::canFetch( 'PackageImageFile' ) )
return true;
$file = eZHTTPFile::fetch( 'PackageImageFile' );
$result = true;
if ( $file )
{
$mimeData = eZMimeType::findByFileContents( $file->attribute( 'original_filename' ) );
$dir = eZSys::storageDirectory() . '/temp';
eZMimeType::changeDirectoryPath( $mimeData, $dir );
$file->store( false, false, $mimeData );
$persistentData['imagefiles'][] = $mimeData;
$result = false;
}
return $result;
}
示例5: fetchObjectAttributeHTTPInput
function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
{
eZBinaryFileType::checkFileUploads();
if ( $this->isDeletingFile( $http, $contentObjectAttribute ) )
{
return false;
}
if ( !eZHTTPFile::canFetch( $base . "_data_binaryfilename_" . $contentObjectAttribute->attribute( "id" ) ) )
return false;
$binaryFile = eZHTTPFile::fetch( $base . "_data_binaryfilename_" . $contentObjectAttribute->attribute( "id" ) );
$contentObjectAttribute->setContent( $binaryFile );
if ( $binaryFile instanceof eZHTTPFile )
{
$contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
$version = $contentObjectAttribute->attribute( "version" );
/*
$mimeObj = new eZMimeType();
$mimeData = $mimeObj->findByURL( $binaryFile->attribute( "original_filename" ), true );
$mime = $mimeData['name'];
*/
$mimeData = eZMimeType::findByFileContents( $binaryFile->attribute( "original_filename" ) );
$mime = $mimeData['name'];
if ( $mime == '' )
{
$mime = $binaryFile->attribute( "mime_type" );
}
$extension = eZFile::suffix( $binaryFile->attribute( "original_filename" ) );
$binaryFile->setMimeType( $mime );
if ( !$binaryFile->store( "original", $extension ) )
{
eZDebug::writeError( "Failed to store http-file: " . $binaryFile->attribute( "original_filename" ),
"eZBinaryFileType" );
return false;
}
$binary = eZBinaryFile::fetch( $contentObjectAttributeID, $version );
if ( $binary === null )
$binary = eZBinaryFile::create( $contentObjectAttributeID, $version );
$orig_dir = $binaryFile->storageDir( "original" );
$binary->setAttribute( "contentobject_attribute_id", $contentObjectAttributeID );
$binary->setAttribute( "version", $version );
$binary->setAttribute( "filename", basename( $binaryFile->attribute( "filename" ) ) );
$binary->setAttribute( "original_filename", $binaryFile->attribute( "original_filename" ) );
$binary->setAttribute( "mime_type", $mime );
$binary->store();
$filePath = $binaryFile->attribute( 'filename' );
$fileHandler = eZClusterFileHandler::instance();
$fileHandler->fileStore( $filePath, 'binaryfile', true, $mime );
$contentObjectAttribute->setContent( $binary );
}
return true;
}
示例6: fetchHTTPFile
/**
* Fetches the HTTP-File into $file and fills in MIME-Type information into $mimeData.
*
* @return bool false if something went wrong.
*/
function fetchHTTPFile($httpFileIdentifier, &$errors, &$file, &$mimeData)
{
$returnCode = eZHTTPFile::canFetch($httpFileIdentifier, 0);
if ($returnCode !== eZHTTPFile::UPLOADEDFILE_OK && $returnCode !== true) {
switch ($returnCode) {
case eZHTTPFile::UPLOADEDFILE_DOES_NOT_EXIST:
$errors[] = array('description' => ezpI18n::tr('kernel/content/upload', 'A file is required for upload, no file were found.'));
break;
case eZHTTPFile::UPLOADEDFILE_EXCEEDS_PHP_LIMIT:
case eZHTTPFile::UPLOADEDFILE_EXCEEDS_MAX_SIZE:
$errors[] = array('description' => ezpI18n::tr('kernel/content/upload', 'The uploaded file size is above the maximum limit.'));
break;
case eZHTTPFile::UPLOADEDFILE_MISSING_TMP_DIR:
case eZHTTPFile::UPLOADEDFILE_CANT_WRITE:
case eZHTTPFile::UPLOADEDFILE_UNKNOWN_ERROR:
$errors[] = array('description' => ezpI18n::tr('kernel/content/upload', 'A system error occured while writing the uploaded file.'));
break;
}
return false;
}
$file = eZHTTPFile::fetch($httpFileIdentifier);
if (!$file instanceof eZHTTPFile) {
$errors[] = array('description' => ezpI18n::tr('kernel/content/upload', 'Expected a eZHTTPFile object but got nothing.'));
return false;
}
$mimeData = eZMimeType::findByFileContents($file->attribute("original_filename"));
return true;
}
示例7: checkRelationActions
function checkRelationActions($module, $class, $object, $version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage)
{
$http = eZHTTPTool::instance();
if ($module->isCurrentAction('BrowseForObjects')) {
$objectID = $object->attribute('id');
$assignedNodes = $object->attribute('assigned_nodes');
$assignedNodesIDs = array();
foreach ($assignedNodes as $node) {
$assignedNodesIDs = $node->attribute('node_id');
}
unset($assignedNodes);
eZContentBrowse::browse(array('action_name' => 'AddRelatedObject', 'description_template' => 'design:content/browse_related.tpl', 'content' => array('object_id' => $objectID, 'object_version' => $editVersion, 'object_language' => $editLanguage), 'keys' => array('class' => $class->attribute('id'), 'class_id' => $class->attribute('identifier'), 'classgroup' => $class->attribute('ingroup_id_list'), 'section' => $object->attribute('section_id')), 'ignore_nodes_select' => $assignedNodesIDs, 'from_page' => $module->redirectionURI('content', 'edit', array($objectID, $editVersion, $editLanguage, $fromLanguage))), $module);
return eZModule::HOOK_STATUS_CANCEL_RUN;
}
if ($module->isCurrentAction('UploadFileRelation')) {
$objectID = $object->attribute('id');
$section = eZSection::fetch($object->attribute('section_id'));
$navigationPart = false;
if ($section) {
$navigationPart = $section->attribute('navigation_part_identifier');
}
$location = false;
if ($module->hasActionParameter('UploadRelationLocation')) {
$location = $module->actionParameter('UploadRelationLocation');
}
// We only do direct uploading if we have the uploaded HTTP file
// if not we need to go to the content/upload page.
if (eZHTTPFile::canFetch('UploadRelationFile')) {
$upload = new eZContentUpload();
if ($upload->handleUpload($result, 'UploadRelationFile', $location, false)) {
$relatedObjectID = $result['contentobject_id'];
if ($relatedObjectID) {
$db = eZDB::instance();
$db->begin();
$object->addContentObjectRelation($relatedObjectID, $editVersion);
$db->commit();
}
}
} else {
eZContentUpload::upload(array('action_name' => 'RelatedObjectUpload', 'description_template' => 'design:content/upload_related.tpl', 'navigation_part_identifier' => $navigationPart, 'content' => array('object_id' => $objectID, 'object_version' => $editVersion, 'object_language' => $editLanguage), 'keys' => array('class' => $class->attribute('id'), 'class_id' => $class->attribute('identifier'), 'classgroup' => $class->attribute('ingroup_id_list'), 'section' => $object->attribute('section_id')), 'result_action_name' => 'UploadedFileRelation', 'ui_context' => 'edit', 'result_module' => array('content', 'edit', array($objectID, $editVersion, $editLanguage, $fromLanguage))), $module);
return eZModule::HOOK_STATUS_CANCEL_RUN;
}
}
if ($module->isCurrentAction('DeleteRelation')) {
$objectID = $object->attribute('id');
if ($http->hasPostVariable('DeleteRelationIDArray')) {
$relationObjectIDs = $http->postVariable('DeleteRelationIDArray');
} else {
$relationObjectIDs = array();
}
$db = eZDB::instance();
$db->begin();
foreach ($relationObjectIDs as $relationObjectID) {
$object->removeContentObjectRelation($relationObjectID, $editVersion);
}
$db->commit();
}
if ($module->isCurrentAction('NewObject')) {
if ($http->hasPostVariable('ClassID')) {
if ($http->hasPostVariable('SectionID')) {
$sectionID = $http->postVariable('SectionID');
} else {
$sectionID = 0;
/* Will be changed later */
}
$contentClassID = $http->postVariable('ClassID');
$class = eZContentClass::fetch($contentClassID);
$db = eZDB::instance();
$db->begin();
$relatedContentObject = $class->instantiate(false, $sectionID);
$db->commit();
$newObjectID = $relatedContentObject->attribute('id');
$relatedContentVersion = $relatedContentObject->attribute('current');
if ($relatedContentObject->attribute('can_edit')) {
$db = eZDB::instance();
$db->begin();
$assignmentHandler = new eZContentObjectAssignmentHandler($relatedContentObject, $relatedContentVersion);
$sectionID = (int) $assignmentHandler->setupAssignments(array('group-name' => 'RelationAssignmentSettings', 'default-variable-name' => 'DefaultAssignment', 'specific-variable-name' => 'ClassSpecificAssignment', 'section-id-wanted' => true, 'fallback-node-id' => $object->attribute('main_node_id')));
$http->setSessionVariable('ParentObject', array($object->attribute('id'), $editVersion, $editLanguage));
$http->setSessionVariable('NewObjectID', $newObjectID);
/* Change section ID to the same one as the main node placement */
$db->query("UPDATE ezcontentobject SET section_id = {$sectionID} WHERE id = {$newObjectID}");
$db->commit();
$module->redirectToView('edit', array($relatedContentObject->attribute('id'), $relatedContentObject->attribute('current_version'), false));
} else {
$db = eZDB::instance();
$db->begin();
$relatedContentObject->purge();
$db->commit();
}
return;
}
}
}
示例8: array
}
if ($http->hasPostVariable('CancelButton')) {
$csvFilePath = '';
return $module->redirectToView('subscription_list', array($nodeId));
} elseif ($http->hasPostVariable('ImportButton')) {
// check if user has rights to import the users
$user = eZUser::currentUser();
$access = $user->hasAccessTo('newsletter', 'subscription_list_csvimport_import');
if ($access['accessWord'] == 'yes') {
$importCsvFile = true;
} else {
return $module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel');
}
}
// upload csv and store data
if (eZHTTPFile::canFetch('UploadCsvFile') && $importId == 0) {
$importType = 'cjwnl_csv';
$dataText = '';
$remoteId = false;
//$remoteId = 'csv:' . md5( $csvFilePath );
// create new Import Object
$importObject = CjwNewsletterImport::create($listContentObjectId, $importType, $note, $dataText, $remoteId);
$importObject->store();
$binaryFile = eZHTTPFile::fetch('UploadCsvFile');
$filePathUpload = $binaryFile->attribute('filename');
$fileSep = eZSys::fileSeparator();
// $fileSize = filesize( $filePathUpload );
//$siteDir = eZSys::siteDir();
$dir = eZSys::varDirectory() . $fileSep . 'cjw_newsletter' . $fileSep . 'csvimport';
$importId = $importObject->attribute('id');
$fileName = $importId . '-' . date("Ymd-His", $importObject->attribute('created')) . '-' . $binaryFile->attribute('original_filename');
示例9: makeErrorArray
}
}
else
{
eZDebug::writeError( "Cannot import document, supplied placement nodeID is not valid." );
$tpl->setVariable( 'error', makeErrorArray( eZOOImport::ERROR_PLACEMENTINVALID,
ezpI18n::tr( 'extension/ezodf/import/error', "Cannot import document, supplied placement nodeID is not valid." ) ) );
}
// $tpl->setVariable( 'oo_mode', 'imported' );
}
else
{
$tpl->setVariable( 'oo_mode', 'browse' );
if( eZHTTPFile::canFetch( "oo_file" ) )
{
$file = eZHTTPFile::fetch( "oo_file" );
if ( $file )
{
if ( $file->store() )
{
$fileName = $file->attribute( 'filename' );
$originalFileName = $file->attribute( 'original_filename' );
// If we have the NodeID do the import/replace directly
if ( $http->sessionVariable( 'oo_direct_import_node' ) )
{
$nodeID = $http->sessionVariable( 'oo_direct_import_node' );
示例10: fetchObjectAttributeHTTPInput
function fetchObjectAttributeHTTPInput($http, $base, $contentObjectAttribute)
{
eZMediaType::checkFileUploads();
$classAttribute = $contentObjectAttribute->contentClassAttribute();
$player = $classAttribute->attribute("data_text1");
$pluginPage = eZMediaType::pluginPage($player);
$contentObjectAttributeID = $contentObjectAttribute->attribute("id");
$version = $contentObjectAttribute->attribute("version");
$width = $http->postVariable($base . "_data_media_width_" . $contentObjectAttribute->attribute("id"));
$height = $http->postVariable($base . "_data_media_height_" . $contentObjectAttribute->attribute("id"));
$quality = $http->hasPostVariable($base . "_data_media_quality_" . $contentObjectAttribute->attribute("id")) ? $http->postVariable($base . "_data_media_quality_" . $contentObjectAttribute->attribute("id")) : null;
if ($http->hasPostVariable($base . "_data_media_controls_" . $contentObjectAttribute->attribute("id"))) {
$controls = $http->postVariable($base . "_data_media_controls_" . $contentObjectAttribute->attribute("id"));
} else {
$controls = null;
}
$media = eZMedia::fetch($contentObjectAttributeID, $version);
if ($media == null) {
$media = eZMedia::create($contentObjectAttributeID, $version);
}
$media->setAttribute("contentobject_attribute_id", $contentObjectAttributeID);
$media->setAttribute("version", $version);
$media->setAttribute("width", $width);
$media->setAttribute("height", $height);
$media->setAttribute("quality", $quality);
$media->setAttribute("controls", $controls);
$media->setAttribute("pluginspage", $pluginPage);
if ($http->hasPostVariable($base . "_data_media_is_autoplay_" . $contentObjectAttribute->attribute("id"))) {
$media->setAttribute("is_autoplay", true);
} else {
$media->setAttribute("is_autoplay", false);
}
if ($http->hasPostVariable($base . "_data_media_has_controller_" . $contentObjectAttribute->attribute("id"))) {
$media->setAttribute("has_controller", true);
} else {
$media->setAttribute("has_controller", false);
}
if ($http->hasPostVariable($base . "_data_media_is_loop_" . $contentObjectAttribute->attribute("id"))) {
$media->setAttribute("is_loop", true);
} else {
$media->setAttribute("is_loop", false);
}
$mediaFilePostVarName = $base . "_data_mediafilename_" . $contentObjectAttribute->attribute("id");
if (eZHTTPFile::canFetch($mediaFilePostVarName)) {
$mediaFile = eZHTTPFile::fetch($mediaFilePostVarName);
} else {
$mediaFile = null;
}
if ($mediaFile instanceof eZHTTPFile) {
$mimeData = eZMimeType::findByFileContents($mediaFile->attribute("original_filename"));
$mime = $mimeData['name'];
if ($mime == '') {
$mime = $mediaFile->attribute("mime_type");
}
$extension = eZFile::suffix($mediaFile->attribute("original_filename"));
$mediaFile->setMimeType($mime);
if (!$mediaFile->store("original", $extension)) {
eZDebug::writeError("Failed to store http-file: " . $mediaFile->attribute("original_filename"), "eZMediaType");
return false;
}
$orig_dir = $mediaFile->storageDir("original");
eZDebug::writeNotice("dir={$orig_dir}");
$media->setAttribute("filename", basename($mediaFile->attribute("filename")));
$media->setAttribute("original_filename", $mediaFile->attribute("original_filename"));
$media->setAttribute("mime_type", $mime);
$filePath = $mediaFile->attribute('filename');
$fileHandler = eZClusterFileHandler::instance();
$fileHandler->fileStore($filePath, 'media', true, $mime);
} else {
if ($media->attribute('filename') == '') {
$media->remove();
return false;
}
}
$media->store();
$contentObjectAttribute->setContent($media);
return true;
}
示例11: print
if ( $http->hasPostVariable( 'NodeID' ) );
$nodeID = $http->postVariable( 'NodeID' );
if ( $http->hasPostVariable( 'ImportType' ) );
$importType = $http->postVariable( 'ImportType' );
// User authentication
$user = eZUser::loginUser( $username, $password );
if ( $user == false )
{
print( 'problem:Authentication failed' );
eZExecution::cleanExit();
}
if ( !eZHTTPFile::canFetch( 'File' ) )
{
print( 'problem:Can\'t fetch HTTP file.' );
eZExecution::cleanExit();
}
$file = eZHTTPFile::fetch('File');
$fileName = $file->attribute( 'filename' );
$originalFilename = $file->attribute('original_filename');
$content = base64_decode( file_get_contents( $fileName ) );
$fd = fopen( $fileName, 'w' );
fwrite( $fd, $content );
fclose( $fd );
示例12: array
$subscription = eZSubscription::create($subscriptionListID, $data[$labelMap['firstname']][$rowIndex], $data[$labelMap['name']][$rowIndex], $data[$labelMap['mobile']][$rowIndex], $data[$labelMap['email']][$rowIndex]);
$subscription->setAttribute('status', eZSubscription::StatusApproved);
$subscription->publish();
}
}
}
}
}
$http->removeSessionVariable('CSVData');
return $Module->redirectToView('subscription_list', array($subscriptionList->attribute('url_alias')));
}
}
}
}
$data = array();
if (eZHTTPFile::canFetch('UploadCSVFile')) {
$binaryFile = eZHTTPFile::fetch('UploadCSVFile');
$parser = new eZCSVParser($binaryFile->attribute('filename'), $http->hasPostVariable('FirstRowLabel') ? true : false, $delimiter);
$data = $parser->data();
$http->setSessionVariable('CSVData', $data);
} else {
if ($http->hasSessionVariable('CSVData')) {
$data = $http->sessionVariable('CSVData');
}
}
$tpl = eZNewsletterTemplateWrapper::templateInit();
$tpl->setVariable('subscriptionList', $subscriptionList);
$tpl->setVariable('data', $data);
$tpl->setVariable('CSVDelimiter', $delimiter);
if ($http->hasPostVariable('RowNum')) {
$tpl->setVariable('RowNum', $http->postVariable('RowNum'));
示例13: fetchHTTPFile
function fetchHTTPFile($httpFileIdentifier, &$errors, &$file, &$mimeData)
{
if (!eZHTTPFile::canFetch($httpFileIdentifier)) {
$errors[] = array('description' => ezpI18n::tr('kernel/content/upload', 'A file is required for upload, no file were found.'));
return false;
}
$file = eZHTTPFile::fetch($httpFileIdentifier);
if (!$file instanceof eZHTTPFile) {
$errors[] = array('description' => ezpI18n::tr('kernel/content/upload', 'Expected a eZHTTPFile object but got nothing.'));
return false;
}
$mimeData = eZMimeType::findByFileContents($file->attribute("original_filename"));
return false;
}
示例14: fetchCollectionAttributeHTTPInput
function fetchCollectionAttributeHTTPInput($collection, $collectionAttribute, $http, $base, $contentObjectAttribute)
{
EnhancedeZBinaryFileType::checkFileUploads();
if (eZHTTPFile::canFetch($base . "_data_enhancedbinaryfilename_" . $contentObjectAttribute->attribute("id")) != eZHTTPFile::UPLOADEDFILE_OK) {
return false;
}
//Check allowed file type - must do it here,again - otherwise an illegal
//file will still be created in the storage directory
$binaryFile = eZHTTPFile::fetch($base . "_data_enhancedbinaryfilename_" . $contentObjectAttribute->attribute("id"));
if (!$binaryFile) {
return eZInputValidator::STATE_INVALID;
}
$moduleINI = eZINI::instance('module.ini.append.php', 'settings');
$allowed = $moduleINI->variable('AllowedFileTypes', 'AllowedFileTypeList');
// $binaryFile->attribute( 'mime_type_part' ) not always the extension
$extension = preg_replace('/.*\\.(.+?)$/', '\\1', $binaryFile->attribute("original_filename"));
if (!in_array(strtolower($extension), $allowed)) {
$contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'Failed to store file. Only the following file types are allowed: %1.'), implode(", ", $allowed));
return eZInputValidator::STATE_INVALID;
}
//$contentObjectAttribute->setContent( $binaryFile );
if ($binaryFile instanceof eZHTTPFile) {
//clean up older files.
$moduleINI = eZINI::instance('module.ini.append.php', 'settings');
$maxFiles = $moduleINI->variable('RemoveFiles', 'MaxFiles');
$downloadPath = $moduleINI->variable('RemoveFiles', 'DownloadPath');
$downloadPath = trim($downloadPath, "/");
if (!$downloadPath) {
$downloadPath = 'original/collected';
}
if ($maxFiles > 0) {
$Files = array();
$storageDir = eZSys::storageDirectory();
$fileCollection = eZDir::recursiveFindRelative($storageDir, $downloadPath, '.*');
if (count($fileCollection) >= $maxFiles) {
foreach ($fileCollection as $fileItem) {
$lastModified = filemtime($storageDir . '/' . $fileItem);
$Files[$fileItem] = filemtime($storageDir . '/' . $fileItem);
}
asort($Files, SORT_NUMERIC);
while (count($Files) >= $maxFiles) {
$removeFile = key($Files);
if (file_exists($storageDir . '/' . $removeFile)) {
if (!unlink($storageDir . '/' . $removeFile)) {
eZDebug::writeError("Failed to delete file: " . $storageDir . '/' . $removeFile, "EnhancedeZBinaryFileType");
return false;
}
}
array_shift($Files);
}
}
}
//end cleanup
// $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
//$version = $contentObjectAttribute->attribute( "version" );
$mimeData = eZMimeType::findByFileContents($binaryFile->attribute("original_filename"));
//Nice name but it still uses the extension to set the mimetype and therefore can be bogus
$mime = $mimeData['name'];
if ($mime == '') {
$mime = $binaryFile->attribute("mime_type");
}
$extension = eZFile::suffix($binaryFile->attribute("original_filename"));
$binaryFile->setMimeType($mime);
if (!$binaryFile->store($downloadPath, $extension)) {
eZDebug::writeError("Failed to store http-file: " . $binaryFile->attribute("original_filename"), "EnhancedeZBinaryFileType");
return false;
}
//Adds xmltext to collection attribute with file info to data_text attribute
$doc = new DOMDocument('1.0', 'utf-8');
$root = $doc->createElement('binaryfile-info');
$binaryFileList = $doc->createElement('binaryfile-attributes');
foreach ($binaryFile as $key => $binaryFileItem) {
$binaryFileElement = $doc->createElement($key, $binaryFileItem);
$binaryFileList->appendChild($binaryFileElement);
}
$root->appendChild($binaryFileList);
$doc->appendChild($root);
$docText = EnhancedeZBinaryFileType::domString($doc);
$collectionAttribute->setAttribute('data_text', $docText);
}
return true;
}
示例15: fileupload
/**
* Saves a file for import option
* @param array $args First value: handler id, second value: option id
* @return string saved file name
* @throws SQLIImportRuntimeException
*/
public static function fileupload($args)
{
if (count($args) !== 2) {
throw new SQLIImportRuntimeException('Invalid arguments');
}
$handler = $args[0];
$option = $args[1];
$importINI = eZINI::instance('sqliimport.ini');
$handlerSection = $handler . '-HandlerSettings';
if (!$importINI->hasSection($handlerSection)) {
throw new SQLIImportRuntimeException('No config for handler ' . $handler);
}
$options = $importINI->variable($handlerSection, 'Options');
if (!in_array($option, $options)) {
throw new SQLIImportRuntimeException('Invalid option ' . $option);
}
$returnCode = eZHTTPFile::canFetch('Filedata', 0);
if ($returnCode !== eZHTTPFile::UPLOADEDFILE_OK && $returnCode !== true) {
throw new SQLIImportRuntimeException('Invalid uploaded file');
}
$file = eZHTTPFile::fetch('Filedata');
if (!$file instanceof eZHTTPFile) {
throw new SQLIImportRuntimeException('Invalid uploaded file');
}
if (self::checkFileFormat($handler, $option, $file)) {
$dir = $importINI->variable('OptionsGUISettings', 'UploadedFilesDir') . DIRECTORY_SEPARATOR . $handler . DIRECTORY_SEPARATOR . $option;
//temporarily store uploaded file before clusterizing it
$file->store($dir);
eZClusterFileHandler::instance()->fileStore($file->attribute('filename'), false, true);
return $file->attribute('filename');
}
}