Forums / Developer / Importing PDF files - Storing ezbinaryfile types using PHP

Importing PDF files - Storing ezbinaryfile types using PHP

Author Message

Betsy Gamrat

Saturday 20 January 2007 8:54:19 pm

How can I store PDF files using a PHP import?

What I really need is the function call that will accept the name of the file and any other parameters, index the file (if necessary), and then store the file.

Thank you in advance!

kracker (the)

Sunday 21 January 2007 1:23:36 am

I like the idea!

Still my first thought is while you could write this import script.
Could you also take advantage of 'webdav' to drag and drop,
your files into a folder for storage and separately run the
search index update ezcli php script.

Though I've not done a large publish via 'webdav', I wouldn't
be surprised if it failed in the middle of a large session / large
number of files. Possibly bringing us all back to the question of this topic :\

So ... anyone write a script like this yet willing to <i>share your information ...</i>

<i>
I am always jack's smirking face,
//kracker
Mama-se, Mama-sa, Mama-macosa ...

D12 - Macosa (feat. Outsidaz)</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Betsy Gamrat

Sunday 21 January 2007 10:45:33 am

There is a post in this forum describing file imports, but it looked a little outdated.

I was hoping someone would have done this recently with 3.7+ and would post the magic code (calls into ezbinaryfile).

Collecting my courage to use the ezbinaryfile interface PHP ...

:)

kracker (the)

Sunday 21 January 2007 11:17:34 am

I did a little searching and found a similar thread topic,
<i>http://ez.no/community/forum/developer/creating_a_simple_content_object_via_php</i>

<i>//kracker

KoRn - Fake</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Betsy Gamrat

Sunday 21 January 2007 4:58:53 pm

Kracker,

Thank you!

That was the post I was referring to - but I couldn't find it quickly.

I looked at the eZ PHP code and I'm going to try to just call the eZ code. I don't like to copy the eZ code into mine, because if eZ changes, it is more likely that my code will still be compatible - since it will simply call eZ.

I'll just backup the database before I do any testing.

kracker (the)

Sunday 21 January 2007 5:36:02 pm

Good Luck Betsy,

Looking forward to the results of your testing.

Perhaps it can result in a useful standalone contribution.

<i>//kracker

Telepopmusik - Smile</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Kristof Coomans

Monday 22 January 2007 1:51:40 am

You can create an object and use the insertRegularFile function of the file attribute to fill it. It will use the datatype's implementation of the insertRegularFile function to store a file in the attribute. Of course only certain datatypes (ezimage, ezbinaryfile) implement this.

Another way is using eZContentUpload, which will create the right content class according to the file's mime type.

include_once( 'kernel/classes/ezcontentupload.php' );
$upload = new eZContentUpload();
    
$success = $upload->handleLocalFile( $result, $localFilePath, 'auto', false, $name );
print_r( $result );

Note that there are some unclosed bugs involved in both situations, but patches are attached: http://issues.ez.no/9312 and http://issues.ez.no/9736

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Betsy Gamrat

Tuesday 23 January 2007 5:27:14 am

kracker and Kristof,

Thank you for your ideas.

I contacted eZ support, and Kristian Hole was a great help.

I liked the <b>insertRegularFile</b> function and used it. It first goes through ezdatatype, and ultimately, in this case, ends in ezbinaryfiletype.php.

I suspect this code will work with images, too.

There is a bugfix that was necessary. The link is at the end of this post.

:)

<b>Solution</b> <i>(based on the ubiquitous create.php script)</i>


/* eZBinaryFile includes */
include_once( "kernel/classes/ezdatatype.php" );

...
        // Loop through the attributes, processing each one
        foreach (array_keys($contentObjectAttributes) as $key)
        {
                $contentObjectAttribute =& $contentObjectAttributes[$key];
                $contentClassAttribute =& $contentObjectAttribute->contentClassAttribute();
                $attributeName = $contentClassAttribute->attribute('name');

                switch ($attributeName)
                {
                        case 'Filename to store':
                                store($contentClassAttribute->attribute('identifier'),$contentObject,$contentObjectVersion,false,$contentObjectAttribute,$uPDFfilename );
                                $contentObjectAttribute->store();
                                break;
...

// This function stores the file.
function store($id,&$contentObject,$contentObjectVersion,$objectLanguage,&$contentObjectAttribute,$sourceFile )
{
$dataMap =& $contentObject->dataMap();
$status = $dataMap[$id]->insertRegularFile( $contentObject, $contentObjectVersion, $objectLanguage,$sourceFile,$result );
}

http://issues.ez.no/IssueView.php?Id=10070