wp_upload_dir come ottenere solo il nome della directory.
-
-
`basename ($ uploads ['baseurl'])`?`basename($uploads['baseurl'])` ?
- 5
- 2012-04-04
- onetrickpony
-
1 risposta
- voti
-
- 2012-04-04
Questo è ciò che ottieni dallafunzione:
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] => )
Quindipuoi ottenere (come ha sottolineato @OneTrickPony),ilnome della cartella/directory con
echo wp_basename( $uploads['baseurl'] );
Se staieseguendomultisitoe hai definito la costante
UPLOADS
,accederai daUPLOADS
oBLOGUPLOADDIR
.<"EDIT"
Peri sitimultipli,otterrai qualcosa delgenere:
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] => , )
Doveil "2" dopo
sites
è l'ID delblogThis 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-
-grazie atuttie due lì.basenamee dopo qualche ricerca anche wp_basename,penserei.- thanks to both of you there. basename and after some research wp_basename too I'd reckon.
- 2
- 2012-04-04
- orionrush
-
wp_basename è la "versionei18nfriendly dibasename ()" 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
Immagino cheper alcuni sarebbe ungioco da ragazzi,ma ho difficoltà a ottenere soloilnome della directory del caricamento,nonilpercorso completo,sono arrivato a questopunto:
qualcuno ha qualcheidea? grazieper aver condiviso latuaesperienza...