我想这对一些人来说是轻而易举的事,但我很难只获得上传的目录名,而不是完整路径,我已经走到了这一步:
$uploads = wp_upload_dir();
$upload_path = $uploads[\'baseurl\']; // now how to get just the directory name?
有人有什么想法吗?感谢分享您的经验。我想这对一些人来说是轻而易举的事,但我很难只获得上传的目录名,而不是完整路径,我已经走到了这一步:
$uploads = wp_upload_dir();
$upload_path = $uploads[\'baseurl\']; // now how to get just the directory name?
有人有什么想法吗?感谢分享您的经验。这是您从函数中得到的结果:
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] =>
)
因此,您可以使用echo wp_basename( $uploads[\'baseurl\'] );
如果您正在运行多站点并定义了常量UPLOADS
, 然后从UPLOADS
或BLOGUPLOADDIR
.EDIT
对于多站点,您会得到如下结果: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] => ,
)
“2”之后的位置sites
是博客的ID我在获取图像时获得404状态,http仍然包含该图像。图像显示在浏览器中,但404代码中断了一些应用程序。对wp内容/上载/的调用被重定向到。htaccess:<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\\.php$ - [L] RewriteRule (.*) /index.php?getfile=$1 [L] </IfModule>&