問題描述
我想像這樣會很輕鬆,但是我很難得到上傳的目錄名稱 – 而不是完整的路徑 – 我已經得到了這麼多的結果:
$uploads = wp_upload_dir();
$upload_path = $uploads['baseurl']; // now how to get just the directory name?
有誰有什麼想法?感謝您分享您的經驗。 。 。
最佳解決方案
這是你從功能中得到的:
Array
(
[path] => C:developmentxampphtdocsexample.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] =>
)
所以你可以得到 (作為 @OneTrickPony 指出),文件夾/目錄名稱
echo wp_basename( $uploads['baseurl'] );
如果您正在運行多站點,並且定義了常量 UPLOADS
,則可以從 UPLOADS
或 BLOGUPLOADDIR
訪問它。
編輯
對於多元素,你會得到這樣的東西:
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] => ,
)
sites
之後的”2″ 是博客的 ID
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。