Page 1 of 1

Create thumb problem

Posted: Sat Feb 20, 2010 5:04 am
by enfix
Hi,
I've a big problem :?
I tried to create a photo gallery.
My problem is in this function. It get a photo from directory and make a thumb.

Code: Select all

function MakeThumb($file){
                
    $path_parts=pathinfo($file);
    
    $extension=$path_parts['extension'];
    $dir=$path_parts['dirname'];
    $file_name=$path_parts['filename'];
    
    if (!(file_exists($dir."/thumb")))
    {
      mkdir($dir."/thumb/", 0777);
      chmod($dir."/thumb", 0777);  
    }
    
    $src_img=false;    
    $thumb_file=$dir."/thumb/".$file_name."_thumb.".$extension;
    if (!file_exists($thumb_file) || !CheckThumb($file,$thumb_file)){
    
            if (preg_match('/jpg|jpeg/i',$extension)){
                $src_img=imagecreatefromjpeg($file)  or die ("Image not found!");
            }
            if (preg_match('/png/i',$extension)){
                $src_img=imagecreatefrompng($file)  or die ("Image not found!");
            }
            if (preg_match('/gif/i',$extension)){
                $src_img=imagecreatefromgif($file)  or die ("Image not found!");
            }
            
            if ($src_img) {
                $width = imagesx($src_img);
                $height = imagesy($src_img);
                $twidth = 150; # width of the thumb 160 pixel
                $theight = $twidth * $height / $width; # calculate height
                $thumb = @imagecreatetruecolor ($twidth, $theight) or die ("Can't create Image!");
                imagecopyresized($thumb, $src_img, 0, 0, 0, 0, $twidth, $theight, $width, $height);
                
                if (preg_match('/jpg|jpeg/i',$extension)){
                    Imagejpeg($thumb,$dir."/thumb/".$file_name."_thumb.".$extension);
                }
                if (preg_match('/png/i',$extension)){
                    Imagepng($thumb,$dir."/thumb/".$file_name."_thumb.".$extension);
                }
                if (preg_match('/gif/i',$extension)){
                    Imagegif($thumb,$dir."/thumb/".$file_name."_thumb.".$extension);
    
                }
                
                
                
            }
            
    }
    
    return $thumb_file;
        
}
The problem is that in localhost it work, but on the remote host don't work.
The function don't create "thumb" directory.
Any solution ?
Gd libraries are enabled.
Permission problem ?
How can i solve it ?

Re: Create thumb problem

Posted: Sat Feb 20, 2010 6:15 am
by netgoons
I guess you need to make the parent file writable. Better yet create a thumb directory on your server and override the directory creation code. You dont need it to be dynamic. You already know where to save the file. Just go to the folder on your host that contains thumb dir and create a thing dir. Then allow read-write access. 777. I guess that should do.

Re: Create thumb problem

Posted: Sat Feb 20, 2010 6:29 am
by enfix
I don't understand your solution.
netgoons wrote:Better yet create a thumb directory on your server and override the directory creation code.
What do you mean ?
If i create "thumb" dir manually and i set it to 777, function don't create the thumbnail inside thumb dir.
The problem is for file and dir.

The parent dir of this folder has 777.

Sorry for my bad english :)

Re: Create thumb problem

Posted: Sat Feb 20, 2010 8:07 am
by netgoons
Can you print the path completely once and see if it is pointed to the right place. On server it might change a bit especially if you have multiple domain on the same hosting account. Print the total file path of the thumb file once and cross chk.

Re: Create thumb problem

Posted: Mon Feb 22, 2010 7:23 am
by enfix
Maibe i found solution.....
The problem can be about the safe_mode in php settings: it's set to on, but usually it's set to off.
Could this be the problem?