EDIT: Problem solved:
Stupid little twit that I am, I had neglected to give the file a name. $testSiteDir was a path with no filename. How can a file be saved without a name! D’Oh!
sorry 😉
I know there’s lots of similar questions around and I’ve been reading through them but since I’ve sort of had to build a hybrid of all the tutorials and articles I’ve got some code which I hoped would work but doesn’t.
I did at one point manage to create copies of the images into the folder I wanted using the copy() function to move it, which worked. But since I want to resize it I need to use GD (as far as I can tell)
here’s my code:
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);
}
}
When I try using the above I get the error that I don’t have permission to write to that folder: Unable to open ‘C:/xampp/htdocs/test’ for writing: Permission denied in…
I’ve got three text books and read a bunch of articles about images and php, I haven’t seen anywhere where it tells me what to do
what’s going wrong 🙂
Setting write permissions on Windows can be less than obvious.
Try these instructions http://drupal.org/node/202491 and see how you get on.
If you use Xampp as a PHP installation, it usually seems to propagate write permissions through the whole directory structure of htdocs. Very handy. Not sure why it hasn’t done it for you.
EDIT: just noticed that the Drupal page relates to IIS. Maybe this will be better…
Apache on windows server can't write to file