Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Hi!

I'm just wondering how I can output the filename of an editble type='file' instead of the full path?

Code: Select all
<cms:editable name='uploaded_pdf' label='Downloadable PDF File' type='file'/>

<a href="<cms:show uploaded_pdf />"><cms:show uploaded_pdf /></a>

Which will generate:

< href="http://domain.com/files/document123.pdf">http://domain.com/files/document123.pdf</a>
How I'd like it:
< href="http://domain.com/files/document123.pdf">document123.pdf</a>



Many thanks :)
Code: Select all
<cms:set pdf_id = "<cms:php>global $FUNCS; $data = $FUNCS->unserialize( '<cms:get_custom_field 'uploaded_pdf' masterpage=k_template_name/>'); print_r($data[file_id]);</cms:php>" />

<cms:query sql="SELECT f.file_disk_name AS `name` FROM <cms:php>echo K_TBL_ATTACHMENTS;</cms:php> f WHERE f.attach_id = <cms:show file_id />">

<cms:set pdf_handle = "<cms:concat name '.pdf'/>" />

<cms:set pdf_fullpath = "<cms:php>global $Config; echo 'http://domain.com/files'.'/';</cms:php><cms:show pdf_handle />"  />

<a href="<cms:show pdf_fullpath />"><cms:show pdf_handle/></a>

</cms:query>

This is an adaptation of the code I use on a project with a similar problem. If it is on a clonable page you would need to add change the first part to

Code: Select all
 [code]<cms:set pdf_id = "<cms:php>global $FUNCS; $data = $FUNCS->unserialize( '<cms:get_custom_field 'uploaded_pdf' masterpage=k_template_name/ page=k_page_name>'); print_r($data[file_id]);</cms:php>" />

I have not tested this and I'm sure theres a simpler solution than directly querying the database but this should work.
Thanks for the quick reply ! I seem not to have any luck with the SQL query, not sure what I'm doing wrong :)
I'm just getting :
Code: Select all
Could not successfully run query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0, 1000' at line 1
Okay, I got it working using some regex instead :)

Below is the solution if anyone else want to do the same:

Code: Select all
<cms:set uploaded_pdf_filename="<cms:php>
    echo(preg_replace( '!^.*/([^/]+)$!',\"$1\", \"<cms:show uploaded_pdf/>\" ));
</cms:php>" />

   <cms:show uploaded_pdf_filename />


Thanks for leading me in the right direction keakie :)
4 posts Page 1 of 1
cron