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

eZ debug

Timing: Jan 18 2025 15:19:14
Script start
Timing: Jan 18 2025 15:19:14
Module start 'content'
Timing: Jan 18 2025 15:19:15
Module end 'content'
Timing: Jan 18 2025 15:19:15
Script end

Main resources:

Total runtime1.2419 sec
Peak memory usage4,096.0000 KB
Database Queries211

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0053 587.9688180.7969
Module start 'content' 0.00531.1282 768.7656663.3672
Module end 'content' 1.13350.1083 1,432.1328345.0234
Script end 1.2418  1,777.1563 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00380.3097210.0002
Check MTime0.00150.1201210.0001
Mysql Total
Database connection0.00060.048610.0006
Mysqli_queries1.145592.23942110.0054
Looping result0.00220.17862090.0000
Template Total1.213997.720.6070
Template load0.00160.130420.0008
Template processing1.212397.615020.6061
Template load and register function0.00010.010310.0001
states
state_id_array0.00080.061910.0008
state_identifier_array0.00140.109020.0007
Override
Cache load0.00160.1248670.0000
Sytem overhead
Fetch class attribute can translate value0.00160.129940.0004
Fetch class attribute name0.00110.0855110.0001
XML
Image XML parsing0.00240.197340.0006
class_abstraction
Instantiating content class attribute0.00000.0028160.0000
General
dbfile0.00250.2049410.0001
String conversion0.00000.000330.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
8content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
8content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
13content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 37
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs