Creating thumbnails PHP problem

Posted by Wayne on Stack Overflow See other posts from Stack Overflow or by Wayne
Published on 2010-05-30T12:34:22Z Indexed on 2010/05/30 12:42 UTC
Read the original article Hit count: 296

I have this source code where I got it from net tutsplus. I have configured it and made it work in one PHP file. It does work by transferring the original image, but it does not generate to the thumbnails folder.

<?php

$final_width_of_image = 100;
$path_to_image_directory = "../../img/events/" . urldecode($_GET['name']) . "/";
$path_to_thumbs_directory = "../../img/events/" . urldecode($_GET['name']) . "/thumbnails/";

function createThumbnail($filename)
{
    if(preg_match('/[.](jpg)$/', $filename)) 
    {
        $im = imagecreatefromjpeg($path_to_image_directory . $filename);
    } 
    elseif(preg_match('/[.](gif)$/', $filename)) 
    {
        $im = imagecreatefromgif($path_to_image_directory . $filename);
    } 
    elseif(preg_match('/[.](png)$/', $filename)) 
    {
        $im = imagecreatefrompng($path_to_image_directory . $filename);
    }

    $ox = imagesx($im);
    $oy = imagesy($im);

    $nx = $final_width_of_image;
    $ny = floor($oy * ($final_width_of_image / $ox));

    $nm = imagecreatetruecolor($nx, $ny);

    imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);

    imagejpeg($nm, $path_to_thumbs_directory . $filename);
    $tn = '<img src="' . $path_to_thumbs_directory . $filename . '" alt="image" />';
    echo $tn;
}

if(isset($_FILES['fupload'])) {

    if(preg_match('/[.](jpg)|(gif)|(png)$/', $_FILES['fupload']['name'])) {

        $filename = $_FILES['fupload']['name'];
        $source = $_FILES['fupload']['tmp_name'];
        $target = $path_to_image_directory . $filename;

        move_uploaded_file($source, $target);

        createThumbnail($filename);
    }
}

?>

Basically it is supposed to generate a thumbnail of the uploaded image and store the original image into a different folder.

The paths are correct, it works by getting the folder name in the URL, it does work, but nothing works for the thumbnails folder.

BEFORE you ask this related question, yes, thumbnails generation does work on my server by the PHP GD, I have tested it separately. So this is not the problem. :)

How do I get this to work? :(

© Stack Overflow or respective owner

Related posts about php

Related posts about image-processing