Forum Moderators: coopster

Message Too Old, No Replies

imagecreatefromjpeg permission

         

NeilsPHP

4:04 am on Nov 2, 2008 (gmt 0)

10+ Year Member



i am running into a problem.I am trying to create a thumbnail and while doing so,the script (which I am calling from public_html) works great but i have to have public_html permission 0777 (which is scary).If not,I will throw fatal error of memory size allocation overflow.
I tried to put the script in another folder above public_html and gave 0777 permission,but it still won't work.any ideas ?
I am using shared server and no chance of increasing memory.(if it was memory prob,it won't work despite permission levels i guess)

function createthumb($current_name,$new_name,$new_w,$new_h)
{
$system=explode(".",$current_name);
if (preg_match("/jpg¦jpeg/",$system[1])){$src_img=imagecreatefromjpeg($current_name);}
if (preg_match("/JPG¦JPEG/",$system[1])){$src_img=imagecreatefromjpeg($current_name);}
if (preg_match("/GIF¦gif/",$system[1])){$src_img=imagecreatefromgif($current_name);}
if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($current_name);}

$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y)
{
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y)
{
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y)
{
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);

if (preg_match("/png/",$system[1]))
{
imagepng($dst_img,$new_name);
} else {
imagejpeg($dst_img,$new_name);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}

cameraman

3:52 pm on Nov 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you get this sorted out?
Have you tried putting it below public_html, say maybe public_html/uploads and chmodding uploads to 0777?
If $newname starts with a / it may want to put the file in public_html regardless of where the script resides. Remember that you can specify an absolute location to put it where you really want it regardless of the script's location, for example strip the directory stuff from new_name:
$new_name = basename($new_name);
$new_path = 'home/users/myname/public_html/uploads/' . $new_name;
imagepng($dst_img,$new_path);

eeek

2:44 am on Nov 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If not,I will throw fatal error of memory size allocation overflow.

Have you tried increasing the memory limit in php.ini?