Ayon Posted March 16, 2009 Share Posted March 16, 2009 hey ok.. so i've been going on for about 3 hours now with this code, and it's still not working. it's my first attempt on doing this. my problem is that it doesn't return any errors but it's still not working at all :S what i want to do is to create a copy of the image inside a folder named thumbs. and the thumbs is inside the same folder as the original image.. but when i check the thumbs folder it's empty... <?php function MiscCreateThumb($path,$file,$width,$height) { // Check if all variables contains info if (!empty($path) && !empty($file) && !empty($width) && !empty($height)) { // Set the path's $cpath = $path.'/'.$file; $dest = $path.'/'.'thumbs/'.$file; // Check if folder exists if (is_dir($path)) { // Get file extension $ext = end(explode(".",$file)); // Declare valid extensions $validExt = array('jpg','gif','png','jpeg','JPG','GIF','PNG','JPEG'); // Check if current extension is valid if (in_array($ext,$validExt)) { // Declare the right action for the given extension if (preg_match('/jpg|jpeg|JPG|JPEG/',$ext)) { $sourcefile = imagecreatefromjpeg($cpath); } if (preg_match('/gif|GIF/',$ext)) { $sourcefile = imagecreatefromgif($cpath); } if (preg_match('/png|PNG/',$ext)) { $sourcefile = imagecreatefrompng($cpath); } list($owidth,$oheight) = getimagesize($cpath); $newimg = imagecreatetruecolor($width,$height); imagecopyresampled($newimg,$sourcefile,0,0,0,0,$width,$height,$owidth,$oheight); if (preg_match('/jpg|jpeg|JPG|JPEG/',$ext)) { imagejpeg($newimg,$file); } if (preg_match('/gif|GIF/',$ext)) { imagegif($newimg,$file); } if (preg_match('/png|PNG/',$ext)) { imagepng($newimg,$file); } } } } } ?> Thanks In Advance - Ayon Link to comment https://forums.phpfreaks.com/topic/149633-solved-problems-making-a-thumbnail/ Share on other sites More sharing options...
pkSML Posted March 16, 2009 Share Posted March 16, 2009 Here's the last few lines of your code: <?php if (preg_match('/jpg|jpeg|JPG|JPEG/',$ext)) { imagejpeg($newimg,$file); } if (preg_match('/gif|GIF/',$ext)) { imagegif($newimg,$file); } if (preg_match('/png|PNG/',$ext)) { imagepng($newimg,$file); }?> Shouldn't you use your $dest variable? <?php if (preg_match('/jpg|jpeg|JPG|JPEG/',$ext)) { imagejpeg($newimg,$dest); } if (preg_match('/gif|GIF/',$ext)) { imagegif($newimg,$dest); } if (preg_match('/png|PNG/',$ext)) { imagepng($newimg,$dest); }?> Link to comment https://forums.phpfreaks.com/topic/149633-solved-problems-making-a-thumbnail/#findComment-785758 Share on other sites More sharing options...
Ayon Posted March 16, 2009 Author Share Posted March 16, 2009 it now returns the following error Warning: imagejpeg() [function.imagejpeg]: Unable to open '../../images/uploads/games/16/thumbs/' for writing: Is a directory in /srv/nannyhome/wiifan/webroot/live/admin/inc/functions/misc.php on line 132 the folder is 0777 EDIT: Solved... had to add $file behind $dest... Thanks !! Link to comment https://forums.phpfreaks.com/topic/149633-solved-problems-making-a-thumbnail/#findComment-785766 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.