Champ File : récupérer en php uniquement le nom du fichier

More
2 years 7 months ago - 2 years 7 months ago #83985 by bendeb
Bonjour,

Avec le champ file, j'uploade un fichier.
Je souhaiterai dans mon template, avec php, afficher au sein d'une url, uniquement le nom du fichier uploadé (et son extension).
Une syntaxe de ce genre mais qui affiche uniquement le nom du fichier :
Code:
<?php echo $this->fields['mon_champ']->display; ?>
Dans les paramètres du champ, on peut faire en sorte d'afficher uniquement le nom du fichier, mais ça ne l'isole pas du reste.
Et donc si je mets ceci dans mon template :
Code:
https://www.test/<?php echo $this->fields['mon_champ']->display; ?>
et que mon fichier s'appelle fichier.jpg, le rendu sur le site ne donne pas www.test/fichier.jpg mais :
www.test/s/%3Cbr%20class=%22fcclear%22%2...iv%3E%3C/fieldset%3E
Du coup ça ne fonctionne pas.


Merci d'avance pour votre aide.

Flexicontent 4.1.0b1
Joomla 3.9.18
Last edit: 2 years 7 months ago by bendeb.

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago #83986 by micker

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago #83989 by bendeb
Merci Micker,
Ca ne semble pas fonctionner.

J'ai mis ceci dans item.php :
Code:
<?php $html = FlexicontentFields::getFieldDisplay  (   $item, 'mon_champ', null, 'display', 'item'  ); echo $html; echo $item->fields['mon_champ']->display;   // AFTER CALLING getFieldDisplay(), you can also use these arrays print_r($item->fields['cb_cartes_upload_carte']->filedata); // e.g. size, absolute paths, etc print_r($item->fields['cb_cartes_upload_carte']->url); // file urls print_r($item->fields['cb_cartes_upload_carte']->abspath); // file absolute pats ?>
Et ça m'affiche ceci : getFieldDisplay(): empty item data given

 

Flexicontent 4.1.0b1
Joomla 3.9.18

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago - 2 years 7 months ago #83990 by bendeb
Si je mets ceci, c'est déjà un peu mieux :
Code:
<?php    $html = FlexicontentFields::getFieldDisplay ($item, 'mon_champ', null, 'display', 'item');   print_r($this->fields['cb_cartes_upload_carte']->url); // file urls print_r($this->fields['cb_cartes_upload_carte']->abspath); // file absolute pats   ?>

Mais print_r avec l'url me donne l'adresse du fichier à download.
Et abspath me donne le chemin absolu, et pas juste le nom du fichier.
Par ailleurs, devant chacune de ces infos, j'ai un Array ( [0] => qui s'affiche.

 

Flexicontent 4.1.0b1
Joomla 3.9.18
Last edit: 2 years 7 months ago by bendeb.

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago #83991 by micker
toi ce que tu veus est dans print_r($item->fields->filedata); // e.g. size, absolute paths, etc
il faut que tu fasses un var_dump pour regarder comme est fait la donnée et l'extraire

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago #83995 by bendeb
J'avais déjà fait un var_dump.
Je trouve bien le nom du fichier dans l'attribut filename, abspath, altname ou filename_original, mais je n'arrive pas à afficher juste ce nom de fichier ensuite.
Si je mets :
Code:
$altname = $this->fields['mon_champ']->display->altname; echo $altname;
Rien ne s'affiche. Alors que altname a bien le nom du fichier et son extension quand je fais un var_dump.

Mon but serait de placer ça dans item.php :

www.site.com/ [NOM_DU_FICHIER] en remplaçant [NOM_DU_FICHIER] par un code php qui me sort uniquement le nom du fichier donc (avec ou sans extension, je m'en fout un peu).

 

Flexicontent 4.1.0b1
Joomla 3.9.18

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago #83996 by bendeb
C'est bon, j'ai trouvé, avec altname qui contient le nom du fichier et son extension par défaut (si rien n'est renseigné dans alt donc).
Code:
<?php echo $this->fields['mon_champ']->file_data[0]->altname;?>

 

Flexicontent 4.1.0b1
Joomla 3.9.18

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago #83997 by micker
cool bravo

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago - 2 years 7 months ago #84000 by bendeb
En fait, c'est même mieux de mettre filename plutôt que altname, car Flexicontent renomme les fichiers avec des - au lieu des espaces.

Flexicontent 4.1.0b1
Joomla 3.9.18
Last edit: 2 years 7 months ago by bendeb.

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago #84004 by micker
non tu ne peus pas choisir le dossier de base
mais tu peus definir le mode media (normal) ou secure

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline
Save