woodplease Posted June 8, 2012 Share Posted June 8, 2012 hey, i have some code that uploads an image to a directory, and then creates a thumbnail of that image and stores that in another directory. The uploading of the file works, however after re-sizing the image, i get an error "Warning: imagejpeg() [function.imagejpeg]: Unable to open './images/album_thumb/' for writing: No such file or directory in C:\xampp\htdocs\kens\test2.php on line 43". The directory is there, so i'm not sure why i'm getting the error. Any ideas? $src = ($target.$name.".jpg"); $dest = "./images/album_thumb/"; $img = imagecreatefromjpeg($src); $width = imagesx($img); $height = imagesy($img); $thumbWidth = 10; $new_width = $thumbWidth; $new_height = floor($height * ($thumbWidth / $width)); $tmp_img = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagejpeg($tmp_img, $dest); imagedestroy($tmp_img); imagedestroy($img); $target is the the location of the file from the upload part of the script, and $name is the name of the file Quote Link to comment https://forums.phpfreaks.com/topic/263850-create-thumbnails-after-upload/ Share on other sites More sharing options...
litebearer Posted June 8, 2012 Share Posted June 8, 2012 Simple test (tell us what happens)... $src = ($target.$name.".jpg"); echo $src; ?> <img src="<?php echo $src; ?>"> <?php Quote Link to comment https://forums.phpfreaks.com/topic/263850-create-thumbnails-after-upload/#findComment-1352113 Share on other sites More sharing options...
woodplease Posted June 8, 2012 Author Share Posted June 8, 2012 it outputs "/images/album_photos/img2059005505.jpg" and then displays the image, so its definitely selecting the right image. Quote Link to comment https://forums.phpfreaks.com/topic/263850-create-thumbnails-after-upload/#findComment-1352126 Share on other sites More sharing options...
litebearer Posted June 8, 2012 Share Posted June 8, 2012 try changing this... $dest = "./images/album_thumb/"; to this... $dest = "/images/album_thumb/"; Quote Link to comment https://forums.phpfreaks.com/topic/263850-create-thumbnails-after-upload/#findComment-1352132 Share on other sites More sharing options...
woodplease Posted June 8, 2012 Author Share Posted June 8, 2012 i've tried that, no luck. i've even created a hyperlink to that location to check its accessible, which it is. Quote Link to comment https://forums.phpfreaks.com/topic/263850-create-thumbnails-after-upload/#findComment-1352133 Share on other sites More sharing options...
woodplease Posted June 8, 2012 Author Share Posted June 8, 2012 i've sorted it now, i needed to put the destination in "imagejpeg($tmp_img, "/images/photo_thumbs"). Not sure why it wouldnt let me use the variable though Quote Link to comment https://forums.phpfreaks.com/topic/263850-create-thumbnails-after-upload/#findComment-1352144 Share on other sites More sharing options...
litebearer Posted June 8, 2012 Share Posted June 8, 2012 why??? perhaps... $dest = "./images/album_thumb/"; while the actual folder that works is... "/images/photo_thumbs" Obviously NOT the same folder Quote Link to comment https://forums.phpfreaks.com/topic/263850-create-thumbnails-after-upload/#findComment-1352182 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.