wp_upload_dir wie man nur den Verzeichnisnamen erhält.
-
-
`basename ($ uploads ['baseurl'])`?`basename($uploads['baseurl'])` ?
- 5
- 2012-04-04
- onetrickpony
-
1 Antworten
- Stimmen
-
- 2012-04-04
Folgendeserhalten Sie von der Funktion zurück:
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 können Sie den (wie @OneTrickPony hervorhob) Ordner-/Verzeichnisnamenmit
abrufenecho wp_basename( $uploads['baseurl'] );
Wenn Sie Multisite ausführen und die Konstante
UPLOADS
definiert haben,greifen Sie überUPLOADS
oderBLOGUPLOADDIR
darauf zu.EDIT
Für Multisiteserhalten Sie ungefähr Folgendes:
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] => , )
Wobei die "2"nach
istsites
die ID des BlogsThis 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-
- Danke aneuchbeide.Basisname undnacheinigen Recherchen auch wp_basename würdeich rechnen.- thanks to both of you there. basename and after some research wp_basename too I'd reckon.
- 2
- 2012-04-04
- orionrush
-
wp_basenameist die "i18n-freundliche Version vonbasename ()" 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
Ich stellemir vor,dass diesfüreinige ein Kinderspiel wäre - aberich habe Schwierigkeiten,nur den Verzeichnisnamen des Uploads zuerhalten -nicht den vollständigen Pfad -ichbin so weitgekommen:
hatjemandirgendwelche Ideen? Vielen Dankfür Ihre Erfahrungen...