creating thumbnail images with php - writing permissions
===

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 :)