Passer la navigation

[Résolu] File pdf upload dynamic title

Ce fil est résolu. Voici une description du problème et la solution proposée.

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 Il y a 4 years, 1 month. 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.

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 -

Fuseau horaire du supporter : Asia/Hong_Kong (GMT+08:00)

Ce sujet contient 4 réponses, a 2 voix.

Dernière mise à jour par TomW5440 Il y a 4 years, 1 month.

Assisté par: Luo Yang.

Auteur
Publications
#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>lien caché</u></em>;

Will output result: file1.zip

You can find more options in PHP document:
lien caché

2) Use above shortcode, like this:

<ol>[wpv-for-each field="wpcf-my-file"]
<li><em><u>lien caché</u></em></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.

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

  1. lien caché
  2. [/wpv-for-each]

#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!