0

编辑:问题已解决:我是个愚蠢的小笨蛋,我忽略了给文件命名。$testSiteDir 是一个没有文件名的路径。没有名字怎么能保存文件!哦!对不起 ;)


我知道周围有很多类似的问题,我一直在阅读它们,但由于我不得不构建所有教程和文章的混合体,所以我有一些我希望能工作但没有工作的代码。

我曾经设法将图像的副本创建到我想要使用 copy() 函数移动它的文件夹中,这很有效。但是因为我想调整它的大小,所以我需要使用 GD(据我所知)

这是我的代码:

if (is_dir($BooksDir)) {
if ($dh = opendir($BooksDir)) {
    while (($folder = readdir($dh)) !== false) {
        $count++;
        $exclude = array('.','..','etc.');
        if (!in_array($folder, $exclude)){
            echo '<div ' . ($count&1 ? 'class="oddrow"' : 'class="evenrow"') . '>';
            echo $folder . "<br/>" . $count;
            $subDir = $BooksDir . '/' . $folder;
            $filesnfolders = scandir($subDir);
            foreach ($filesnfolders as $file) {
                $ext = pathinfo($file, PATHINFO_EXTENSION);
                if ($ext == 'jpg' || $ext == 'jpeg' || $ext == 'png' || $ext == 'gif') {
                    if ($ext == 'jpg' || $ext == 'jpeg') {
                        $origimg = imagecreatefromjpeg($subDir. '/' . $file);
                        $thHeight = 100;
                        $thWidth = 100;
                        $mainWidth = imagesx( $origimg );
                        $mainHeight = imagesy( $origimg );
                        $myThumbnail = imagecreatetruecolor($thWidth, $thHeight);
                        imagecopyresampled( $myThumbnail, $origimg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $mainWidth, $mainHeight );
                        imagejpeg( $myThumbnail, $testSiteDir );
                    }
                }
            }
            echo '</div>';
        }
    }
    closedir($dh);
}

}

当我尝试使用上述内容时,我收到了我没有权限写入该文件夹的错误:无法打开'C:/xampp/htdocs/test'进行写入:权限被拒绝...

我有三本教科书,阅读了一堆关于图像和 php 的文章,我还没有看到任何地方告诉我该怎么做

出了什么问题:)

4

1 回答 1

0

在 Windows 上设置写权限可能不太明显。

试试这些说明http://drupal.org/node/202491看看你是怎么开始的。

如果您使用 Xampp 作为 PHP 安装,它通常似乎通过 htdocs 的整个目录结构传播写权限。非常便利。不知道为什么它没有为您完成。

EDIT: just noticed that the Drupal page relates to IIS. Maybe this will be better... Apache on windows server can't write to file

于 2012-07-24T15:51:25.167 回答