Jump to content

Function


WorldDrknss

Recommended Posts

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

Link to comment
Share on other sites

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);
	}
}
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
	}
}
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.