0

我正在编写 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";
}

该链接有效,并将我直接带到图像。我已经尝试了所有我能想到的路径。我查看了使用 PHP 从目录中读取图像,从我所看到的一切来看,它应该可以工作!

有任何想法吗?

编辑 这是我所做的代码更改,试图解决这个问题:

$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.";
}
4

2 回答 2

1

试试这个:

if ($handle = opendir($thumbPath)) 

它可能会有所帮助。

Edit: (Some additional explanation) Variables in single quotes are treated as an ordinary text, and because of that, you're trying to open a directory called $thumbPath, which I suppose doesn't exist.

于 2012-11-30T22:25:51.090 回答
0

I'm not sure what I did, but it's working now.

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

if ($handle = opendir($thumbPath)) 

I'd already tried that url, but maybe I had a missed typo.

于 2012-12-01T05:14:13.667 回答