Create a direct link to a binary file

Author Message

Nicolas Heiringhoff

Wednesday 28 July 2004 3:17:39 am

Hello erveryone,

we have some problems with creating a direct link to a binary file.
The PDF-files we want to offer for download a stored in a certain folder with the node id 296.
From an override-template of another folder in the tree-hierarchy we can grab the content of node 296 with the following code


{* Fetch everything that is under node #296 (children, grand-children, etc.) *}
{let nodes=fetch( 'content', 'tree', hash( 'parent_node_id', 296 ) ) }

{* Loop through the nodes and display their names. *}
{section loop=$nodes}

<br />
    <a href={concat("/content/view/full/",$:item.node_id)|ezurl}>{$:item.data_map.titel.data_text}</a>
    
    <br />
    {$:item.data_map.beschreibung.data_text}
    
    <br />
    
    {$:item.data_map.binaer.data_???}
    
    <br /> 

We can display the attributes title (identifier="titel") and description (identifier="beschreibung") but we can not display the actual file directly (identifier="binaer"), because we do not know the data_map. For the title and the description it is "data_text". We also used data_int before, to display numbers. Which data_map can we use to display the file?

When you click on the link that we generated with the code above, the file plus the filsize is displayed directly by the ezbinaryfile.tpl, that is used there. We want exactly that, but copying the ezbinaryfile.tpl in our override template does not work.

http://www.heiringhoff.de

Roy Bøhmer

Monday 02 August 2004 11:11:53 am

Sorry for the late answer. Hope you already have figured something out.
I've used this code whith success. Hope it helps.

<a href={concat("content/download/",
			$object.id,
			"/",
			$object.data_map.file.id,
			"/file/",
			$object.data_map.file.content.original_filename)|ezurl}>
			{$object.name|wash}</a>

You should replace <i>$object</i> with <i>$:item.object</i> and ensure that the attributename for the binary file in the class is file. If not, replace <i>file</i> with the attributename.

Roy

Nicolas Heiringhoff

Tuesday 03 August 2004 4:00:30 am

Hello Roy,

your code works perfectly fine!

Thank you very much!

Nicolas

http://www.heiringhoff.de

willy jansen

Monday 15 November 2004 9:39:12 am

Congratulations! Would you mind explaining how you solved this and what code you used. For at least one person (me) is looking for a similar solution, but the information above is not sufficient for me.

Nicolas Heiringhoff

Tuesday 16 November 2004 12:17:02 am

Hello Willy,

We put the files (pdfs in our case) in one folder (node id 296).
With the following code we can display the pdfs with a direct download link in a template.


{* Fetch everything that is under node #296 (children, grand-children, etc.) *}
{let nodes=fetch( 'content', 'tree', hash( 'parent_node_id', 296 ) ) }

{* Loop through the nodes and display their names. *}
{section loop=$nodes}


<br />

<span class="fett">{$:item.data_map.titel.data_text}</span>

<br />

{$:item.data_map.beschreibung.data_text}

<br />

<img src={"pdf_mini_icon.png"|ezimage}&nbsp; &nbsp; 

<a href={concat("content/download/",
                        $:item.object.id,
                        "/",
                        $:item.object.data_map.file.id,
                        "/file/",
                        $:item.object.data_map.file.content.original_filename)|ezurl}>
                        {$:item.object.name|wash}</a>

    <br />   
{/section}



{/let}

Regards,
Nico

http://www.heiringhoff.de

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 31 2025 04:33:03
Script start
Timing: Jan 31 2025 04:33:03
Module start 'layout'
Timing: Jan 31 2025 04:33:03
Module start 'content'
Timing: Jan 31 2025 04:33:04
Module end 'content'
Timing: Jan 31 2025 04:33:04
Script end

Main resources:

Total runtime0.9630 sec
Peak memory usage4,096.0000 KB
Database Queries65

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0042 588.2500151.2266
Module start 'layout' 0.00430.0027 739.476636.6797
Module start 'content' 0.00700.9550 776.1563992.7891
Module end 'content' 0.96200.0010 1,768.945315.8281
Script end 0.9630  1,784.7734 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00300.3138160.0002
Check MTime0.00140.1427160.0001
Mysql Total
Database connection0.00070.067810.0007
Mysqli_queries0.905594.0301650.0139
Looping result0.00060.0600630.0000
Template Total0.933196.920.4665
Template load0.00190.196320.0009
Template processing0.931196.691120.4656
Template load and register function0.00140.148110.0014
states
state_id_array0.00140.149510.0014
state_identifier_array0.00140.148420.0007
Override
Cache load0.00160.1707330.0000
Sytem overhead
Fetch class attribute can translate value0.00060.059230.0002
Fetch class attribute name0.00210.219560.0004
XML
Image XML parsing0.00210.219830.0007
class_abstraction
Instantiating content class attribute0.00000.002080.0000
General
dbfile0.00380.3909160.0002
String conversion0.00000.000840.0000
Note: percentages do not add up to 100% because some accumulators overlap

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
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
10content/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
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 27
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs