【问题标题】:creating thumbnail images with php - writing permissions使用 php 创建缩略图 - 写入权限
【发布时间】:2012-07-24 15:44:13
【问题描述】:

编辑:问题已解决: 我是个愚蠢的小笨蛋,我忽略了给文件命名。 $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 的文章,我还没有看到任何地方告诉我该怎么做

出了什么问题:)

【问题讨论】:

  • C:/xampp/htdocs/test 是只读的吗?
  • 我试过用 rightclick->properties->unselect readonly 改变它,但这并没有什么不同,我也试过改变文件夹的所有者,但也没有帮助跨度>

标签: php image gd


【解决方案1】:

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

试试这些说明http://drupal.org/node/202491,看看你会怎么做。

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

编辑:刚刚注意到 Drupal 页面与 IIS 相关。也许这样会更好... Apache on windows server can't write to file

【讨论】:

  • 嘿,阅读那些文章,但我并不聪明,感谢您指出这可能与 Windows 有关,我在 Windows 7 上 - 只需要找出问题所在!为什么一切都那么难!
  • @crazysarah 没那么难,疯子。您可以通过选择“Everyone”并允许该用户写入目录来向自己证明这是可能的。虽然这不是一个好习惯。
猜你喜欢
  • 2023-03-20
  • 2016-10-03
  • 1970-01-01
  • 2011-06-18
  • 1970-01-01
  • 1970-01-01
  • 2015-05-04
  • 2013-10-22
  • 2011-02-25
相关资源
最近更新 更多