Dominik Pich
|
Monday 29 March 2004 5:58:41 am
I imported images using this
/**
* Instantiates the eZImage class and assignes it to the attribute passed.
* Not written by me, downloaded from ez.no!
* @param fileName File's name.
* @param contentObjectAttribute The attribute to modify.
*/
function saveImage( $fileName, &$contentObjectAttribute )
{
//get info from contentObjectAttribute
$contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
$version = $contentObjectAttribute->attribute( "version" );
//create the new ezImage
$image =& eZImage::create( $contentObjectAttributeID , $version );
$image->setAttribute( "contentobject_attribute_id", $contentObjectAttributeID );
$image->setAttribute( "version", $version );
$image->setAttribute( "filename", $fileName );
$image->setAttribute( "original_filename", $fileName );
//set alterative texts
$mimeObj = new eZMimeType();
$mime = $mimeObj->mimeTypeFor( false, $fileName );
$image->setAttribute( "mime_type", $mime );
$image->setAttribute( "alternative_text", $fileName );
$image->store();
//make dir to copy to
$ori_dir = $this->DIRECTORY_STORAGE . '/' . "original/image/";
$ref_dir = $storage_dir . '/' . "reference/image/";
if ( !file_exists( $ori_dir ) )
{
eZDir::mkdir( $ori_dir, 0777, true);
}
if ( !file_exists( $ref_dir ) )
{
eZDir::mkdir( $ref_dir, 0777, true);
}
//copy to storage
$source_file = $this->DIRECTORY_INCOMING . $fileName;
$target_file = $ori_dir . $fileName;
$reference_file = $storage_dir . "/reference/image/" . $fileName;
eZDebug::writeDebug( 'copy from ' . $source_file . ' to ' . $target_file );
copy($source_file, $target_file );
}
Allworks but I keep getting errors:
Error: eZImageManager::createImageAlias Mar 29 2004 16:11:37
The reference alias original file var/notencity/storage/images/alle/364-1-ger-DE/alle. does not exist
Error: Mar 29 2004 16:11:37
Original alias does not exists, cannot create other aliases without it
Error: eZImageManager::createImageAlias Mar 29 2004 16:11:37
Failed creating the referenced alias reference, cannot create alias large
Error: eZImageManager::createImageAlias Mar 29 2004 16:11:37
The reference alias original file var/notencity/storage/images/instrument/367-2-ger-DE/instrument. does not exist
Error: Mar 29 2004 16:11:37
Original alias does not exists, cannot create other aliases without it
Error: eZImageManager::createImageAlias Mar 29 2004 16:11:37
Failed creating the referenced alias reference, cannot create alias large
Error: eZImageManager::createImageAlias Mar 29 2004 16:11:37
The reference alias original file var/notencity/storage/images/genre/370-1-ger-DE/genre. does not exist
Error: Mar 29 2004 16:11:37
Original alias does not exists, cannot create other aliases without it
Error: eZImageManager::createImageAlias Mar 29 2004 16:11:37
Failed creating the referenced alias reference, cannot create alias large
|
Alex Jones
|
Wednesday 31 March 2004 6:15:09 am
The image system was changed with the release of 3.3. According to the New Image System article (http://ez.no/ez_publish/download/changelogs/ez_publish_3_3/new_image_system), the way to import images is different. Instead of the large block of code required previously, you can now import with:
<b>PHP interface</b>
The interface to the image datatype and image system has been modified, this means that import script or other PHP code that used the old eZImage and eZImageVariation directly will need to change the code. While this sounds bad it is actually quite easier to work with the new image system, instead of copying the images and creating references yourself you may now simply pass the image file path to a function in eZImageAliasHandler. Example: $content =& $attribute->content();
// $content is now an instance of eZImageAliasHandler
if ( is_object( $content ) )
{
$content->initializeFromFile( $imageFile );
if ( $content->isStorageRequired() )
{
$content->store();
}
}
I ran into some problems with my import, and with the help of Wenyue, got it working again. I would highly recommend you upgrade to 3.3-4 and try using the above code. If, you cannot upgrade, or if you upgrade and it still doesn't work, post here and I can post the changes we made to the <i>ezimagealiashandler</i> kernal code. But hopefully, they solved those issues in 3.3-4. Alex
Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]
<i>When in doubt, clear the cache.</i>
|