Monday 09 June 2008 8:14:00 am
<b>Hello every body!</b>
I have a problem with eZBinaryFileType (the datatype).
I look to create a file object in my extension to store à pdf. My pdf was juste create on my server at : /home/usr23/ <i>Here the code where I create a new file object and store datas :</i>
<?php //IN a MODULE
define('PATH_PDF','/home/usr23/');
$filename = 'the_temp_name_of_my_file';
//father
$parentNodeID_file = 100;//my father
//class
$class_file = eZContentClass::fetchByIdentifier('file');
$contentObject_file = $class_file->instantiate(eZUser::currentUserID(),EZ_VERSION_STATUS_PUBLISHED);
$contentObject_file->store();
//assignment
$nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObject_file->attribute( 'id' ),
'contentobject_version' => $contentObject_file->attribute( 'current_version' ),
'parent_node' => $parentNodeID_file,
'is_main' => 1 ));
$nodeAssignment->store();
//version
$version_file =& $contentObject_file->version( 1 );
$version_file->setAttribute( 'modified', eZDateTime::currentTimeStamp() );
$version_file->setAttribute( 'status', EZ_VERSION_STATUS_PUBLISHED );
$version_file->store();
//data
$data_map_file =& $contentObject_file->fetchDataMap();
$data_map_file['name']->fromString('filename');
$data_map_file['name']->store();
$data_map_file['description']->fromString('create : '.date('Y-m-d.H-i-s'));
$data_map_file['description']->store();
////////////////////////////////////////////////////////////////////////////////////////TEST
//~ here i found 2 functions how can work :
//~ - insertRegularFile()
//~ - fromString()
//~ fromString() call insertRegularFile()
$result=array();
//$data_map_file['file'] -> insertRegularFile($contentObject_file,$version_file,false,PATH_PDF.$filename,$result);
$data_map_file['file']->fromString($contentObject_file,PATH_PDF.$filename);
print($data_map_file['file']->toString());
////////////////////////////////////////////////////////////////////////////////////////TEST
$data_map_file['file']->store();
//publication
$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObject_file->attribute( 'id' ),'version' => 1) );
?>
In the back-office: If I use insertRegularFile() I obtain a file object how directly propose to download the file. And the file is corrupt. If I edit my object, the file attribute is empty. If I use fromString() I obtain a file object with a normal comportment but the file stored is empty…..
Some one can help me? Thanks.
|