00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 include_once( "kernel/classes/ezdatatype.php" );
00039 include_once( "kernel/classes/datatypes/ezbinaryfile/ezbinaryfile.php" );
00040 include_once( "kernel/classes/ezbinaryfilehandler.php" );
00041 include_once( "lib/ezfile/classes/ezfile.php" );
00042 include_once( "lib/ezutils/classes/ezsys.php" );
00043 include_once( "lib/ezutils/classes/ezmimetype.php" );
00044 include_once( "lib/ezutils/classes/ezhttpfile.php" );
00045
00046 define( 'EZ_DATATYPESTRING_MAX_BINARY_FILESIZE_FIELD', 'data_int1' );
00047 define( 'EZ_DATATYPESTRING_MAX_BINARY_FILESIZE_VARIABLE', '_ezbinaryfile_max_filesize_' );
00048 define( "EZ_DATATYPESTRING_BINARYFILE", "ezbinaryfile" );
00049
00050 class eZBinaryFileType extends eZDataType
00051 {
00052 function eZBinaryFileType()
00053 {
00054 $this->eZDataType( EZ_DATATYPESTRING_BINARYFILE, ezi18n( 'kernel/classes/datatypes', "File", 'Datatype name' ),
00055 array( 'serialize_supported' => true ) );
00056 }
00057
00058
00059
00060
00061 function &fileHandler()
00062 {
00063 return eZBinaryFileHandler::instance();
00064 }
00065
00066
00067
00068
00069
00070 function &viewTemplate( &$contentobjectAttribute )
00071 {
00072 $handler =& $this->fileHandler();
00073 $handlerTemplate = $handler->viewTemplate( $contentobjectAttribute );
00074 $template = $this->DataTypeString;
00075 if ( $handlerTemplate !== false )
00076 $template .= '_' . $handlerTemplate;
00077 return $template;
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 function &editTemplate( &$contentobjectAttribute )
00089 {
00090 $handler =& $this->fileHandler();
00091 $handlerTemplate = $handler->editTemplate( $contentobjectAttribute );
00092 $template = $this->DataTypeString;
00093 if ( $handlerTemplate !== false )
00094 $template .= '_' . $handlerTemplate;
00095 return $template;
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 function &informationTemplate( &$contentobjectAttribute )
00107 {
00108 $handler =& $this->fileHandler();
00109 $handlerTemplate = $handler->informationTemplate( $contentobjectAttribute );
00110 $template = $this->DataTypeString;
00111 if ( $handlerTemplate !== false )
00112 $template .= '_' . $handlerTemplate;
00113 return $template;
00114 }
00115
00116
00117
00118
00119 function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute )
00120 {
00121 if ( $currentVersion != false )
00122 {
00123 $contentObjectAttributeID = $originalContentObjectAttribute->attribute( "id" );
00124 $version = $contentObjectAttribute->attribute( "version" );
00125 $oldfile = eZBinaryFile::fetch( $contentObjectAttributeID, $currentVersion );
00126 if ( $oldfile != null )
00127 {
00128 $oldfile->setAttribute( 'contentobject_attribute_id', $contentObjectAttribute->attribute( 'id' ) );
00129 $oldfile->setAttribute( "version", $version );
00130 $oldfile->store();
00131 }
00132 }
00133 }
00134
00135
00136
00137
00138 function deleteStoredObjectAttribute( &$contentObjectAttribute, $version = null )
00139 {
00140 $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
00141 $sys =& eZSys::instance();
00142 $storage_dir = $sys->storageDirectory();
00143
00144 require_once( 'kernel/classes/ezclusterfilehandler.php' );
00145 if ( $version == null )
00146 {
00147 $binaryFiles = eZBinaryFile::fetch( $contentObjectAttributeID );
00148 eZBinaryFile::remove( $contentObjectAttributeID, null );
00149
00150 foreach ( array_keys( $binaryFiles ) as $key )
00151 {
00152 $binaryFile =& $binaryFiles[$key];
00153
00154 $mimeType = $binaryFile->attribute( "mime_type" );
00155 list( $prefix, $suffix ) = split ('[/]', $mimeType );
00156 $orig_dir = $storage_dir . '/original/' . $prefix;
00157 $fileName = $binaryFile->attribute( "filename" );
00158
00159
00160 $binaryObjectsWithSameFileName = eZBinaryFile::fetchByFileName( $fileName );
00161
00162 $filePath = $orig_dir . "/" . $fileName;
00163 $file = eZClusterFileHandler::instance( $filePath );
00164
00165 if ( $file->exists() and count( $binaryObjectsWithSameFileName ) < 1 )
00166 $file->delete();
00167 }
00168 }
00169 else
00170 {
00171 $count = 0;
00172 $binaryFile = eZBinaryFile::fetch( $contentObjectAttributeID, $version );
00173 if ( $binaryFile != null )
00174 {
00175 $mimeType = $binaryFile->attribute( "mime_type" );
00176 list( $prefix, $suffix ) = split ('[/]', $mimeType );
00177 $orig_dir = $storage_dir . "/original/" . $prefix;
00178 $fileName = $binaryFile->attribute( "filename" );
00179
00180 eZBinaryFile::remove( $contentObjectAttributeID, $version );
00181
00182
00183 $binaryObjectsWithSameFileName = eZBinaryFile::fetchByFileName( $fileName );
00184
00185 $filePath = $orig_dir . "/" . $fileName;
00186 $file = eZClusterFileHandler::instance( $filePath );
00187
00188 if ( $file->exists() and count( $binaryObjectsWithSameFileName ) < 1 )
00189 $file->delete();
00190 }
00191 }
00192 }
00193
00194
00195
00196
00197 function checkFileUploads()
00198 {
00199 $isFileUploadsEnabled = ini_get( 'file_uploads' ) != 0;
00200 if ( !$isFileUploadsEnabled )
00201 {
00202 $isFileWarningAdded =& $GLOBALS['eZBinaryFileTypeWarningAdded'];
00203 if ( !isset( $isFileWarningAdded ) or
00204 !$isFileWarningAdded )
00205 {
00206 eZAppendWarningItem( array( 'error' => array( 'type' => 'kernel',
00207 'number' => EZ_ERROR_KERNEL_NOT_AVAILABLE ),
00208 'text' => ezi18n( 'kernel/classes/datatypes',
00209 'File uploading is not enabled. Please contact the site administrator to enable it.' ) ) );
00210 $isFileWarningAdded = true;
00211 }
00212 }
00213 }
00214
00215
00216
00217
00218
00219 function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00220 {
00221 eZBinaryFileType::checkFileUploads();
00222 $classAttribute =& $contentObjectAttribute->contentClassAttribute();
00223 $mustUpload = false;
00224 $httpFileName = $base . "_data_binaryfilename_" . $contentObjectAttribute->attribute( "id" );
00225 $maxSize = 1024 * 1024 * $classAttribute->attribute( EZ_DATATYPESTRING_MAX_BINARY_FILESIZE_FIELD );
00226
00227 if ( $contentObjectAttribute->validateIsRequired() )
00228 {
00229 $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
00230 $version = $contentObjectAttribute->attribute( "version" );
00231 $binary = eZBinaryFile::fetch( $contentObjectAttributeID, $version );
00232 if ( $binary === null )
00233 {
00234 $mustUpload = true;
00235 }
00236 }
00237
00238 $canFetchResult = eZHTTPFile::canFetch( $httpFileName, $maxSize );
00239 if ( $mustUpload && $canFetchResult == EZ_UPLOADEDFILE_DOES_NOT_EXIST )
00240 {
00241 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00242 'A valid file is required.' ) );
00243 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00244 }
00245 if ( $canFetchResult == EZ_UPLOADEDFILE_EXCEEDS_PHP_LIMIT )
00246 {
00247 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00248 'The size of the uploaded file exceeds the limit set by the upload_max_filesize directive in php.ini.' ) );
00249 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00250 }
00251 if ( $canFetchResult == EZ_UPLOADEDFILE_EXCEEDS_MAX_SIZE )
00252 {
00253 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00254 'The size of the uploaded file exceeds the maximum upload size: %1 bytes.' ), $maxSize );
00255 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00256 }
00257 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00258 }
00259
00260
00261
00262
00263 function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00264 {
00265 eZBinaryFileType::checkFileUploads();
00266 if ( !eZHTTPFile::canFetch( $base . "_data_binaryfilename_" . $contentObjectAttribute->attribute( "id" ) ) )
00267 return false;
00268
00269 $binaryFile =& eZHTTPFile::fetch( $base . "_data_binaryfilename_" . $contentObjectAttribute->attribute( "id" ) );
00270
00271 $contentObjectAttribute->setContent( $binaryFile );
00272
00273
00274
00275 if ( get_class( $binaryFile ) == "ezhttpfile" )
00276 {
00277 $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
00278 $version = $contentObjectAttribute->attribute( "version" );
00279
00280
00281
00282
00283
00284
00285
00286 $mimeData = eZMimeType::findByFileContents( $binaryFile->attribute( "original_filename" ) );
00287 $mime = $mimeData['name'];
00288
00289 if ( $mime == '' )
00290 {
00291 $mime = $binaryFile->attribute( "mime_type" );
00292 }
00293 $extension = eZFile::suffix( $binaryFile->attribute( "original_filename" ) );
00294 $binaryFile->setMimeType( $mime );
00295 if ( !$binaryFile->store( "original", $extension ) )
00296 {
00297 eZDebug::writeError( "Failed to store http-file: " . $binaryFile->attribute( "original_filename" ),
00298 "eZBinaryFileType" );
00299 return false;
00300 }
00301
00302 $binary = eZBinaryFile::fetch( $contentObjectAttributeID, $version );
00303 if ( $binary === null )
00304 $binary = eZBinaryFile::create( $contentObjectAttributeID, $version );
00305
00306 $orig_dir = $binaryFile->storageDir( "original" );
00307
00308 $binary->setAttribute( "contentobject_attribute_id", $contentObjectAttributeID );
00309 $binary->setAttribute( "version", $version );
00310 $binary->setAttribute( "filename", basename( $binaryFile->attribute( "filename" ) ) );
00311 $binary->setAttribute( "original_filename", $binaryFile->attribute( "original_filename" ) );
00312 $binary->setAttribute( "mime_type", $mime );
00313
00314 $binary->store();
00315
00316
00317
00318 require_once( 'kernel/classes/ezclusterfilehandler.php' );
00319 $filePath = $binaryFile->attribute( 'filename' );
00320 $fileHandler = eZClusterFileHandler::instance();
00321 $fileHandler->fileStore( $filePath, 'binaryfile', true, $mime );
00322
00323 $contentObjectAttribute->setContent( $binary );
00324 }
00325 return true;
00326 }
00327
00328
00329
00330
00331 function storeObjectAttribute( &$contentObjectAttribute )
00332 {
00333 }
00334
00335 function customObjectAttributeHTTPAction( $http, $action, &$contentObjectAttribute )
00336 {
00337 eZBinaryFileType::checkFileUploads();
00338 if( $action == "delete_binary" )
00339 {
00340 $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
00341 $version = $contentObjectAttribute->attribute( "version" );
00342 $this->deleteStoredObjectAttribute( $contentObjectAttribute, $version );
00343 }
00344 }
00345
00346
00347
00348
00349
00350 function isHTTPFileInsertionSupported()
00351 {
00352 return true;
00353 }
00354
00355
00356
00357
00358
00359 function isRegularFileInsertionSupported()
00360 {
00361 return true;
00362 }
00363
00364
00365
00366
00367
00368 function insertHTTPFile( &$object, $objectVersion, $objectLanguage,
00369 &$objectAttribute, &$httpFile, $mimeData,
00370 &$result )
00371 {
00372 $result = array( 'errors' => array(),
00373 'require_storage' => false );
00374 $errors =& $result['errors'];
00375 $attributeID = $objectAttribute->attribute( 'id' );
00376
00377 $binary = eZBinaryFile::fetch( $attributeID, $objectVersion );
00378 if ( $binary === null )
00379 $binary = eZBinaryFile::create( $attributeID, $objectVersion );
00380
00381 $httpFile->setMimeType( $mimeData['name'] );
00382
00383 $db =& eZDB::instance();
00384 $db->begin();
00385
00386 if ( !$httpFile->store( "original", false, false ) )
00387 {
00388 $errors[] = array( 'description' => ezi18n( 'kernel/classes/datatypes/ezbinaryfile',
00389 'Failed to store file %filename. Please contact the site administrator.', null,
00390 array( '%filename' => $httpFile->attribute( "original_filename" ) ) ) );
00391 return false;
00392 }
00393
00394
00395 $filePath = $binary->attribute( 'filename' );
00396
00397 $binary->setAttribute( "contentobject_attribute_id", $attributeID );
00398 $binary->setAttribute( "version", $objectVersion );
00399 $binary->setAttribute( "filename", basename( $httpFile->attribute( "filename" ) ) );
00400 $binary->setAttribute( "original_filename", $httpFile->attribute( "original_filename" ) );
00401 $binary->setAttribute( "mime_type", $mimeData['name'] );
00402
00403 $binary->store();
00404
00405
00406
00407 require_once( 'kernel/classes/ezclusterfilehandler.php' );
00408 $filePath = $httpFile->attribute( 'filename' );
00409 $fileHandler = eZClusterFileHandler::instance();
00410 $fileHandler->fileStore( $filePath, 'binaryfile', true, $mimeData['name'] );
00411 $objectAttribute->setContent( $binary );
00412
00413 $db->commit();
00414
00415 $objectAttribute->setContent( $binary );
00416
00417 return true;
00418 }
00419
00420
00421
00422
00423
00424 function insertRegularFile( &$object, $objectVersion, $objectLanguage,
00425 &$objectAttribute, $filePath,
00426 &$result )
00427 {
00428 $result = array( 'errors' => array(),
00429 'require_storage' => false );
00430 $errors =& $result['errors'];
00431 $attributeID = $objectAttribute->attribute( 'id' );
00432
00433 $binary = eZBinaryFile::fetch( $attributeID, $objectVersion );
00434 if ( $binary === null )
00435 $binary = eZBinaryFile::create( $attributeID, $objectVersion );
00436
00437 $fileName = basename( $filePath );
00438 $mimeData = eZMimeType::findByFileContents( $filePath );
00439 $storageDir = eZSys::storageDirectory();
00440 list( $group, $type ) = explode( '/', $mimeData['name'] );
00441 $destination = $storageDir . '/original/' . $group;
00442
00443 if ( !file_exists( $destination ) )
00444 {
00445 if ( !eZDir::mkdir( $destination, eZDir::directoryPermission(), true ) )
00446 {
00447 return false;
00448 }
00449 }
00450
00451
00452
00453 $fileSuffix = eZFile::suffix( $fileName );
00454
00455 if( $fileSuffix )
00456 $fileSuffix = '.' . $fileSuffix;
00457
00458 $fileBaseName = basename( $fileName, $fileSuffix );
00459
00460 $destFileName = md5( $fileBaseName . microtime() . mt_rand() ) . $fileSuffix;
00461 $destination = $destination . '/' . $destFileName;
00462
00463 copy( $filePath, $destination );
00464
00465
00466 require_once( 'kernel/classes/ezclusterfilehandler.php' );
00467 $fileHandler = eZClusterFileHandler::instance();
00468 $fileHandler->fileStore( $destination, 'binaryfile', true, $mimeData['name'] );
00469
00470
00471 $binary->setAttribute( "contentobject_attribute_id", $attributeID );
00472 $binary->setAttribute( "version", $objectVersion );
00473 $binary->setAttribute( "filename", $destFileName );
00474 $binary->setAttribute( "original_filename", $fileName );
00475 $binary->setAttribute( "mime_type", $mimeData['name'] );
00476
00477 $binary->store();
00478
00479 $objectAttribute->setContent( $binary );
00480 return true;
00481 }
00482
00483
00484
00485
00486
00487 function hasStoredFileInformation( &$object, $objectVersion, $objectLanguage,
00488 &$objectAttribute )
00489 {
00490 return true;
00491 }
00492
00493
00494
00495
00496
00497 function storedFileInformation( &$object, $objectVersion, $objectLanguage,
00498 &$objectAttribute )
00499 {
00500 $binaryFile = eZBinaryFile::fetch( $objectAttribute->attribute( "id" ),
00501 $objectAttribute->attribute( "version" ) );
00502 if ( $binaryFile )
00503 {
00504 return $binaryFile->storedFileInfo();
00505 }
00506 return false;
00507 }
00508
00509
00510
00511
00512 function handleDownload( &$object, $objectVersion, $objectLanguage,
00513 &$objectAttribute )
00514 {
00515 $binaryFile = eZBinaryFile::fetch( $objectAttribute->attribute( "id" ),
00516 $objectAttribute->attribute( "version" ) );
00517
00518 $contentObjectAttributeID = $objectAttribute->attribute( 'id' );
00519 $version = $objectAttribute->attribute( "version" );
00520
00521 if ( $binaryFile )
00522 {
00523 $db =& eZDB::instance();
00524 $db->query( "UPDATE ezbinaryfile SET download_count=(download_count+1)
00525 WHERE
00526 contentobject_attribute_id=$contentObjectAttributeID AND version=$version" );
00527 return true;
00528 }
00529 return false;
00530 }
00531
00532 function fetchClassAttributeHTTPInput( &$http, $base, &$classAttribute )
00533 {
00534 $filesizeName = $base . EZ_DATATYPESTRING_MAX_BINARY_FILESIZE_VARIABLE . $classAttribute->attribute( 'id' );
00535 if ( $http->hasPostVariable( $filesizeName ) )
00536 {
00537 $filesizeValue = $http->postVariable( $filesizeName );
00538 $classAttribute->setAttribute( EZ_DATATYPESTRING_MAX_BINARY_FILESIZE_FIELD, $filesizeValue );
00539 }
00540 }
00541
00542
00543
00544 function title( &$contentObjectAttribute, $name = "original_filename" )
00545 {
00546 $value = false;
00547 $binaryFile = eZBinaryFile::fetch( $contentObjectAttribute->attribute( 'id' ),
00548 $contentObjectAttribute->attribute( 'version' ) );
00549 if ( is_object( $binaryFile ) )
00550 $value = $binaryFile->attribute( $name );
00551
00552 return $value;
00553 }
00554
00555 function hasObjectAttributeContent( &$contentObjectAttribute )
00556 {
00557 $binaryFile = eZBinaryFile::fetch( $contentObjectAttribute->attribute( "id" ),
00558 $contentObjectAttribute->attribute( "version" ) );
00559 if ( !$binaryFile )
00560 return false;
00561 return true;
00562 }
00563
00564 function &objectAttributeContent( $contentObjectAttribute )
00565 {
00566 $binaryFile = eZBinaryFile::fetch( $contentObjectAttribute->attribute( "id" ),
00567 $contentObjectAttribute->attribute( "version" ) );
00568 if ( !$binaryFile )
00569 {
00570 $attrValue = false;
00571 return $attrValue;
00572 }
00573 return $binaryFile;
00574 }
00575
00576
00577
00578
00579 function isIndexable()
00580 {
00581 return true;
00582 }
00583
00584 function &metaData( &$contentObjectAttribute )
00585 {
00586 $binaryFile =& $contentObjectAttribute->content();
00587
00588 $metaData = "";
00589 if ( get_class( $binaryFile ) == "ezbinaryfile" )
00590 {
00591 $metaData = $binaryFile->metaData();
00592 }
00593 return $metaData;
00594 }
00595
00596
00597
00598
00599 function serializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
00600 {
00601 $maxSize = $classAttribute->attribute( EZ_DATATYPESTRING_MAX_BINARY_FILESIZE_FIELD );
00602 $attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'max-size', $maxSize,
00603 array( 'unit-size' => 'mega' ) ) );
00604 }
00605
00606
00607
00608
00609 function unserializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
00610 {
00611 $maxSize = $attributeParametersNode->elementTextContentByName( 'max-size' );
00612 $sizeNode = $attributeParametersNode->elementByName( 'max-size' );
00613 $unitSize = $sizeNode->attributeValue( 'unit-size' );
00614 $classAttribute->setAttribute( EZ_DATATYPESTRING_MAX_BINARY_FILESIZE_FIELD, $maxSize );
00615 }
00616
00617
00618
00619
00620
00621 function toString( $objectAttribute )
00622 {
00623 $binaryFile = $objectAttribute->content();
00624
00625 if ( is_object( $binaryFile ) )
00626 {
00627 return implode( '|', array( $binaryFile->attribute( 'filepath' ), $binaryFile->attribute( 'original_filename' ) ) );
00628 }
00629 else
00630 return '';
00631 }
00632
00633
00634
00635 function fromString( &$objectAttribute, $string )
00636 {
00637 if( !$string )
00638 return true;
00639
00640 $result = array();
00641 return $this->insertRegularFile( $objectAttribute->attribute( 'object' ),
00642 $objectAttribute->attribute( 'version' ),
00643 $objectAttribute->attribute( 'language_code' ),
00644 $objectAttribute,
00645 $string,
00646 $result );
00647 }
00648
00649
00650
00651
00652
00653
00654
00655 function serializeContentObjectAttribute( &$package, &$objectAttribute )
00656 {
00657 $node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
00658
00659 $binaryFile = $objectAttribute->attribute( 'content' );
00660 if ( is_object( $binaryFile ) )
00661 {
00662 $fileKey = md5( mt_rand() );
00663 $package->appendSimpleFile( $fileKey, $binaryFile->attribute( 'filepath' ) );
00664
00665 $fileNode = eZDOMDocument::createElementNode( 'binary-file' );
00666 $fileNode->appendAttribute( eZDOMDocument::createAttributeNode( 'filesize', $binaryFile->attribute( 'filesize' ) ) );
00667 $fileNode->appendAttribute( eZDOMDocument::createAttributeNode( 'filename', $binaryFile->attribute( 'filename' ) ) );
00668 $fileNode->appendAttribute( eZDOMDocument::createAttributeNode( 'original-filename', $binaryFile->attribute( 'original_filename' ) ) );
00669 $fileNode->appendAttribute( eZDOMDocument::createAttributeNode( 'mime-type', $binaryFile->attribute( 'mime_type' ) ) );
00670 $fileNode->appendAttribute( eZDOMDocument::createAttributeNode( 'filekey', $fileKey ) );
00671 $node->appendChild( $fileNode );
00672 }
00673
00674 return $node;
00675 }
00676
00677
00678
00679
00680
00681
00682
00683 function unserializeContentObjectAttribute( &$package, &$objectAttribute, $attributeNode )
00684 {
00685 $fileNode = $attributeNode->elementByName( 'binary-file' );
00686 if ( !is_object( $fileNode ) or !$fileNode->hasAttributes() )
00687 {
00688 return;
00689 }
00690
00691 $binaryFile = eZBinaryFile::create( $objectAttribute->attribute( 'id' ), $objectAttribute->attribute( 'version' ) );
00692
00693 $sourcePath = $package->simpleFilePath( $fileNode->attributeValue( 'filekey' ) );
00694
00695 if ( !file_exists( $sourcePath ) )
00696 {
00697 eZDebug::writeError( "The file '$sourcePath' does not exist, cannot initialize file attribute with it",
00698 'eZBinaryFileType::unserializeContentObjectAttribute' );
00699 return false;
00700 }
00701
00702 include_once( 'lib/ezfile/classes/ezdir.php' );
00703 $ini =& eZINI::instance();
00704 $mimeType = $fileNode->attributeValue( 'mime-type' );
00705 list( $mimeTypeCategory, $mimeTypeName ) = explode( '/', $mimeType );
00706 $destinationPath = eZSys::storageDirectory() . '/original/' . $mimeTypeCategory . '/';
00707 if ( !file_exists( $destinationPath ) )
00708 {
00709 $oldumask = umask( 0 );
00710 if ( !eZDir::mkdir( $destinationPath, eZDir::directoryPermission(), true ) )
00711 {
00712 umask( $oldumask );
00713 return false;
00714 }
00715 umask( $oldumask );
00716 }
00717
00718 $basename = basename( $fileNode->attributeValue( 'filename' ) );
00719 while ( file_exists( $destinationPath . $basename ) )
00720 {
00721 $basename = substr( md5( mt_rand() ), 0, 8 ) . '.' . eZFile::suffix( $fileNode->attributeValue( 'filename' ) );
00722 }
00723
00724 include_once( 'lib/ezfile/classes/ezfilehandler.php' );
00725 eZFileHandler::copy( $sourcePath, $destinationPath . $basename );
00726 eZDebug::writeNotice( 'Copied: ' . $sourcePath . ' to: ' . $destinationPath . $basename,
00727 'eZBinaryFileType::unserializeContentObjectAttribute()' );
00728
00729 $binaryFile->setAttribute( 'contentobject_attribute_id', $objectAttribute->attribute( 'id' ) );
00730 $binaryFile->setAttribute( 'filename', $basename );
00731 $binaryFile->setAttribute( 'original_filename', $fileNode->attributeValue( 'original-filename' ) );
00732 $binaryFile->setAttribute( 'mime_type', $fileNode->attributeValue( 'mime-type' ) );
00733
00734 $binaryFile->store();
00735
00736
00737
00738 require_once( 'kernel/classes/ezclusterfilehandler.php' );
00739 $fileHandler = eZClusterFileHandler::instance();
00740 $fileHandler->fileStore( $destinationPath . $basename, 'binaryfile', true );
00741 }
00742
00743 }
00744
00745 eZDataType::register( EZ_DATATYPESTRING_BINARYFILE, "ezbinaryfiletype" );
00746
00747 ?>