編輯:問題解決: 我是愚蠢的小笨蛋,我忽略了爲該文件命名。 $ testSiteDir是一個沒有文件名的路徑。沒有名字的情況下如何保存文件! D'哦! 對不起;)使用php創建縮略圖圖片 - 寫入權限
我知道有很多類似的問題,各地,我一直在通過他們讀,但因爲我已經有點必須建立所有的教程和文章的混合我有一些代碼,我希望工作,但沒有。
我在某一點做了管理創建的圖像副本到我想要使用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'只讀嗎? – Palladium 2012-07-24 15:52:20
我試過用rightclick-> properties-> unselect readonly改變它,但這並沒有改變我的區別,我也試過改變文件夾的所有者,但是這並沒有幫助 – 2012-07-24 16:07:12