wp_upload_dir comment obtenir uniquement le nom du répertoire.
-
-
`basename ($ uploads ['baseurl'])`?`basename($uploads['baseurl'])` ?
- 5
- 2012-04-04
- onetrickpony
-
1 réponses
- votes
-
- 2012-04-04
Voici ce que vous obtenez de lafonction:
Array ( [path] => C:\development\xampp\htdocs\example.com/content/uploads/2012/04 [url] => http://example.com/content/uploads/2012/04 [subdir] => /2012/04 [basedir] => C:\~\example.com/content/uploads [baseurl] => http://example.com/content/uploads [error] => )
Vouspouvez donc obtenir le (comme @OneTrickPony l'a souligné),lenom du dossier/répertoire avec
echo wp_basename( $uploads['baseurl'] );
Si vous utilisez lemultisiteet que vous avez défini la constante
UPLOADS
,vous y accédez depuisUPLOADS
ouBLOGUPLOADDIR
.< EDIT
Pour lesmultisites,vous obtiendrez quelque chose comme ceci:
Array ( [path] => /var/www/example.com/public_html/wp-content/uploads/sites/2/2016/12, [url] => http://example.com/wp-content/uploads/sites/2/2016/12, [subdir] => /2016/12, [basedir] => /var/www/example.com/public_html/wp-content/uploads/sites/2, [baseurl] => http://example.com/wp-content/uploads/sites/2, [error] => , )
Où le "2" après
sites
est l'ID dublogThis is what you get back from the function:
Array ( [path] => C:\development\xampp\htdocs\example.com/content/uploads/2012/04 [url] => http://example.com/content/uploads/2012/04 [subdir] => /2012/04 [basedir] => C:\~\example.com/content/uploads [baseurl] => http://example.com/content/uploads [error] => )
So you can get the (as @OneTrickPony pointed out), folder/directory name with
echo wp_basename( $uploads['baseurl'] );
If you're running multisite and you defined the constant
UPLOADS
, then you access it fromUPLOADS
orBLOGUPLOADDIR
.EDIT
For multisites, you would get something like this:
Array ( [path] => /var/www/example.com/public_html/wp-content/uploads/sites/2/2016/12, [url] => http://example.com/wp-content/uploads/sites/2/2016/12, [subdir] => /2016/12, [basedir] => /var/www/example.com/public_html/wp-content/uploads/sites/2, [baseurl] => http://example.com/wp-content/uploads/sites/2, [error] => , )
Where the "2" after
sites
is the blog's ID-
- Merci à vous deux.basenameet après quelques recherches wp_basename aussije compte.- thanks to both of you there. basename and after some research wp_basename too I'd reckon.
- 2
- 2012-04-04
- orionrush
-
wp_basenameest la "version convivialei18n debasename ()" https://codex.wordpress.org/Function_Reference/wp_basenamewp_basename is the "i18n friendly version of basename()" https://codex.wordpress.org/Function_Reference/wp_basename
- 1
- 2017-08-23
- Chaoley
J'imagine que ce serait unjeu d'enfantpour certains -maisj'ai dumal à obtenir uniquement lenom du répertoire dutéléchargement -pas le chemin complet -je suis arrivéjusqu'ici:
quelqu'un a desidées? Merci d'avoirpartagé votreexpérience...