Skip Navigation

[Resolved] File pdf upload dynamic title

This thread is resolved. Here is a description of the problem and solution.

Problem:

Get file name value from custom file field.

Solution:

It needs custom codes, for example:

https://toolset.com/forums/topic/file-pdf-upload-dynamic-title/#post-2341829

Relevant Documentation:

http://php.net/manual/en/function.pathinfo.php

This support ticket is created 2 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 6.42 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by TomW5440 2 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#2341597

Tell us what you are trying to do?

Hello
So I have a form with repeatable file upload.
When customising the template view loop I'm only able to set a static title for link to the uploaded file. I'm really looking to use a dynamic title based on the uploaded file name. Is there a way to do this please?
Thanks

#2341829

Hello,

There isn't such kind of built-in feature within Toolset plugins, it is possible with some custom codes, for example, the custom file field is using slug "my-file", you can try these:
1) create a custom shortcode [get_mime_type], put below codes into your theme/functions.php:

add_shortcode('get_mime_type', 'get_mime_type_func');
function get_mime_type_func($atts, $content = ''){
    // Attributes
    extract( shortcode_atts(
        array(
            'option' => 'extension',
        ), $atts )
    );
    $content = wpv_do_shortcode($content);
    $path_parts = pathinfo($content);
    $res = '';
    if($path_parts[$option]){
        $res = $path_parts[$option];
    }
    return $res;
}

With above shortcode you can get the file name by specifying the shortcode attribute option="basename", for example:

[get_mime_type option="basename"]<em><u>hidden link</u></em>;

Will output result: file1.zip

You can find more options in PHP document:
hidden link

2) Use above shortcode, like this:

<ol>[wpv-for-each field="wpcf-my-file"]
<li><a href="[types field="my-file" output="raw"][/types]" ><span class="[get_mime_type][types field="my-file" output="raw"][/types][/get_mime_type]">[get_mime_type option="basename"][types field="my-file" output="raw"][/types][/get_mime_type]</span></a></li>
[/wpv-for-each]</ol>

More help:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-for-each
Iterate through multiple items in a post meta field and output the enclosed text for each item. Including Types repeating fields.

#2342025

Thanks Luo this is really appreciated!

Added to theme functions and then short code in Fields and Text but it doesn't seem to be working. I wondered if it was because of the same type commas in the short code as with html so tried changing it so only double quotes were used with href and span. It's still not displaying on front end.

<ol>[wpv-for-each field='wpcf-my-file']

  • [get_mime_type option='basename'][types field='my-file' output='raw'][/types][/get_mime_type]
  • [/wpv-for-each]</ol>

    #2342085

    Please provide a test site with the same problem, fill below private message box with login details, also point out the problem page URL, I need to test and debug it in a live website, thanks

    #2342709

    Thank you I got this working now!