用PHP读取Wordpress目录

用PHP读取Wordpress目录,php,wordpress,plugins,opendir,Php,Wordpress,Plugins,Opendir,我正在编写Wordpress插件,在读取目录中的文件时遇到了问题。这个脚本在wordpress之外运行良好,我不确定问题出在哪里 $thumbPath = '../wp-content/uploads/images/thumbs'; //added for debugging $link = $thumbPath . '/1.jpg'; echo " <a href='" . $link . "'>Link</a><br />"; if ($handle

我正在编写Wordpress插件,在读取目录中的文件时遇到了问题。这个脚本在wordpress之外运行良好,我不确定问题出在哪里

$thumbPath = '../wp-content/uploads/images/thumbs'; 

//added for debugging
$link = $thumbPath . '/1.jpg';
echo " <a href='" . $link . "'>Link</a><br />";

if ($handle = opendir($thumbPath)) 
{  
    echo "here";
}
$thumbPath='../wp content/uploads/images/thumbs';
//为调试添加了
$link=$thumbPath'/1.jpg';
回声“
”; 如果($handle=opendir($thumbPath)) { 呼应“这里”; }
这个链接起作用,直接把我带到图片上。我已经尝试了我能想到的每一种方法。我看了看,从我能看到的一切,它应该是工作

有什么想法吗

编辑 以下是我为解决此问题所做的代码更改:

$upload_dir = wp_upload_dir();
$thumbPath =  realpath($upload_dir['baseurl']) . "/images/thumbs";
echo " <img src='" . $thumbPath . "/1.jpg' /><br />";

if ($handle = opendir($thumbPath)) 
{  //if the directory exists open
    echo "here";
}
else
{
    echo "<br />The damn thing isn't working.";
}
$upload_dir=wp_upload_dir();
$thumbPath=realpath($upload\u dir['baseurl'])。“/images/thumbs”;
回声“
”; 如果($handle=opendir($thumbPath)) {//如果目录存在,请打开 呼应“这里”; } 其他的 { echo“
这该死的东西坏了。”; }
试试这个:

if ($handle = opendir($thumbPath)) 
这可能会有帮助


编辑:(一些附加说明)单引号中的变量被视为普通文本,因此,您试图打开一个名为$thumbPath的目录,我认为它不存在。

我不确定我做了什么,但它现在正在工作

$path = "../blog/wp-content/uploads/images";
$thumbPath = $path . "/thumbs";
$fullPath = $path . "/full";

if ($handle = opendir($thumbPath)) 

我已经试过了那个url,但可能是我漏掉了一个输入错误。

你的WordPress路径正确吗?你确定WP有你认为它的当前目录吗?你的确切意思是什么?就我所知,这个链接是正确的。我在Wordpress外部设置了一个页面,该页面完全符合我的要求,并使用路径“../blog/wp content/uploads/images/thumbs”,该路径在Wordpress内部不起作用,因为Wordpress位于/blog目录中。我还尝试了一个绝对路径,但没有成功。请扩展您的答案,解释单引号在变量插值中的作用使用引号似乎没有什么区别,但感谢您的回复。在这种情况下,您能否更具体地说明“我在读取目录中的文件时遇到问题”?您是否在输出中得到警告或“here”?不,这是我得到的输出:我有一个循环,它将运行特定目录中的所有文件,并为lightbox应用程序创建标记。它在Wordpress之外运行时效果非常好。我不确定,但我发现了一个非常类似的问题,你一定要试试
$thumbPath=plugin\u dir\u path(\uu FILE\uuu)。”/wp内容/上传/图像/拇指'