为什么不能将imagejpeg保存到文件夹中?

I've been truble shooting this for hours and i've been all over the web trying to find the solution to this... Im writing a thumbnale generater in php that should generate a gray scale image and a non gray scale, but i've been running into this error. I have already changed my permissions to 777 and chown to nobody and admin. and this function works as long as I over write an image by the same name, but it cannot store in a file for some reason.

here is the error:

imagejpeg() [function.imagejpeg]: Unable to open '/Applications/XAMPP/xamppfiles/htdocs/images
/thumb/rollover' for writing: Is a directory

here is the code i'm working with.

  $img = imagecreatefromjpeg($grayscale_path);

            imagefilter($img, IMG_FILTER_GRAYSCALE);

            imagejpeg($img, realpath($this->gallery_path .'/thumb/rollover/'));


            imagedestroy($img);

also i've checked many many times to see if the path is correct and it is.

You need to append a filename,

 header("Content-type: image/jpeg"); 
 imagejpeg($img, realpath($this->gallery_path .'/thumb/rollover/filename.jpg'));

in imagejpeg, second parameter is not a path to a dir, but to the actual file you must add "filename.jpg" at the end of the path.