WorldDrknss Posted November 11, 2007 Share Posted November 11, 2007 I am having a problem with the $func (function below) $originals = to C:\srv\www\ournativecreatures/media/pgallery/originals $originals = $dir."originals"; $thepath = pathinfo($orginals."/".$img); $types = array('jpg' => array('imagecreatefromjpeg', 'imagejpeg'), 'jpeg' => array('imagecreatefromjpeg', 'imagejpeg'), 'gif' => array('imagecreatefromgif', 'imagegif'), 'png' => array('imagecreatefrompng', 'imagepng')); $func = $types[$thepath['extension']][0]; $src = $func($originals."/".$img); if you run it php returns a Fatal Error of Function name must be a string for $src = $func($originals."/".$img); Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 11, 2007 Share Posted November 11, 2007 echo $func to see the value of that var and tell us! Quote Link to comment Share on other sites More sharing options...
atlanta Posted November 11, 2007 Share Posted November 11, 2007 doesnt look like $func is a function .. Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 11, 2007 Share Posted November 11, 2007 doesnt look like $func is a function .. yeah but i guess the thread starter do this function teng(){echo 'teng';} $x= 'teng'; $x();//teng Quote Link to comment Share on other sites More sharing options...
Barand Posted November 11, 2007 Share Posted November 11, 2007 I'd check the value of "$thepath['extension']" in case it isn't in your $types array Quote Link to comment Share on other sites More sharing options...
WorldDrknss Posted November 11, 2007 Author Share Posted November 11, 2007 I'd check the value of "$thepath['extension']" in case it isn't in your $types array Thanks, that solved my problem. I should have realized this, since I had to make the same change in another script. Quote Link to comment Share on other sites More sharing options...
WorldDrknss Posted November 11, 2007 Author Share Posted November 11, 2007 Now I need help with Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 13056 bytes) in C:\srv\www\ournativecreatures\scripts\pttn.php on line 29 Here is the full functions function createthumb($img, $size, $dir){ $originals = $dir."originals"; $thumbnails = $dir."thumbnails"; $displayed = $dir."display"; ini_set('memory_limit', "32M"); if(is_file($originals."/".$img)){ if($cursize = getimagesize($originals."/".$img)){ if($size == "th") {$newsize[0] = "170"; $newsize[1] = "127"; $prefix = "th"; $savepath = $thumbnails;} if($size == "dp") {$newsize = setWidthHeight($cursize[0], $cursize[1], 550, 550); $prefix = "dp"; $savepath = $displayed;} $thepath = pathinfo($orginals."/".$img); $dst = imagecreatetruecolor($newsize[0], $newsize[1]); $types = array('jpg' => array('imagecreatefromjpeg', 'imagejpeg'), 'jpeg' => array('imagecreatefromjpeg', 'imagejpeg'), 'gif' => array('imagecreatefromgif', 'imagegif'), 'png' => array('imagecreatefrompng', 'imagepng')); $func = $types[strtolower($thepath['extension'])][0]; $src = $func($originals."/".$img); imagecopyresampled($dst, $src, 0, 0, 0, 0, $newsize[0], $newsize[1], $cursize[0], $cursize[1]); $func = $types[strtolower($thepath['extension'])][1]; $savedir = str_replace(".".$thepath['extension'], "", $savepath."/".$img); $savedir = $savedir . "_".$prefix . "." .$thepath['extension']; $func($dst, $savedir); } } } Quote Link to comment Share on other sites More sharing options...
WorldDrknss Posted November 12, 2007 Author Share Posted November 12, 2007 I increated ini_set('memory_limit', "32M"); to 64M, but is there some other way to achieve this? Quote Link to comment Share on other sites More sharing options...
Dragen Posted November 12, 2007 Share Posted November 12, 2007 I've found in the past that the error is usually caused because the php is trying to do something that will never complete, so it just keeps trying until it hits the max. Go through your code and make sure there's no loops that will just continue if not checked, or dodgy coding that leads the server to nothing. Quote Link to comment Share on other sites More sharing options...
WorldDrknss Posted November 12, 2007 Author Share Posted November 12, 2007 It returns this memory error on line 29 which is $src = $func($originals."/".$img); ptlr.php: <?php include("../maincore.php"); $allowedtypes = array('image/jpeg', 'image/pjpeg', 'image/png', 'image/gif'); $allowedexten = array('jpeg', 'jpg', 'gif', 'png'); $savefolder = $config['photo_dir']."originals"; if(isset($_FILES['uploader'])){ $ext = substr($_FILES['uploader']['name'], strrpos($_FILES['uploader']['name'], '.') + 1); if(in_array(strtolower($ext), $allowedexten)){ if(in_array($_FILES['uploader']['type'], $allowedtypes)){ if($_FILES['uploader']['error'] == 0){ $file_new_name = time()."_".$_FILES['uploader']['name']; $thefile = $savefolder."/".$file_new_name; if(!move_uploaded_file($_FILES['uploader']['tmp_name'], $thefile)){ echo "There was an error uploading the file"; } else { include('pttn.php'); createthumb($file_new_name, 'th', $config['photo_dir']); createthumb($file_new_name, 'dp', $config['photo_dir']); } } else { echo "There was an error"; } } else { echo "There was a problem with filetype"; } } else { echo "There was a problem with extention"; } } else { echo "Oops"; } ?> pttn.php: <?php function setWidthHeight($width, $height, $maxWidth, $maxHeight){ $ret = array($width, $height); $ratio = $width / $height; if($width > $maxWidth || $height > $maxHeight){ $ret[0] = $maxWidth; $ret[1] = $ret[0] / $ratio; if($ret[1] > $maxHeight){ $ret[1] = $maxHeight; $ret[0] = $ret[1] * $ratio; } } return $ret; } function createthumb($img, $size, $dir){ $originals = $dir."originals"; $thumbnails = $dir."thumbnails"; $displayed = $dir."display"; ini_set('memory_limit', "32M"); if(is_file($originals."/".$img)){ if($cursize = getimagesize($originals."/".$img)){ if($size == "th") {$newsize[0] = "170"; $newsize[1] = "127"; $prefix = "th"; $savepath = $thumbnails;} if($size == "dp") {$newsize = setWidthHeight($cursize[0], $cursize[1], 550, 550); $prefix = "dp"; $savepath = $displayed;} $thepath = pathinfo($orginals."/".$img); $dst = imagecreatetruecolor($newsize[0], $newsize[1]); $types = array('jpg' => array('imagecreatefromjpeg', 'imagejpeg'), 'jpeg' => array('imagecreatefromjpeg', 'imagejpeg'), 'gif' => array('imagecreatefromgif', 'imagegif'), 'png' => array('imagecreatefrompng', 'imagepng')); $func = $types[strtolower($thepath['extension'])][0]; $src = $func($originals."/".$img); imagecopyresampled($dst, $src, 0, 0, 0, 0, $newsize[0], $newsize[1], $cursize[0], $cursize[1]); $func = $types[strtolower($thepath['extension'])][1]; $savedir = str_replace(".".$thepath['extension'], "", $savepath."/".$img); $savedir = $savedir . "_".$prefix . "." .$thepath['extension']; $func($dst, $savedir); } } } ?> Quote Link to comment 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.