okay.. what I wanna do is,
1. upload an image into temp folder -- done
2. create a folder -- done
3. create an index.html in the new folder -- done
4. create thumbnail image in the new folder -- page dead without errors
5. copy(rename) the original image into the new folder. -- rename function returns false

and here's my code
My code works perfectly in Window but in Ubuntu. There must be some** server setting issues** I am not aware of.. Please help

$filePath = $tempFolder.$fileName;
$newFolder = ".../"
$indexPatth = $newFolder."index.html";
$thumbnailPath = $newFolder."thumb.jpg";
$renamePath = $newFolder."original.jpg";

if(file_exists($filePath)){

    //make new folder with 777 permission  -- done
    $old = umask(0);
    mkdir($newFolder, 0777);
    chmod($newFolder, 0777);
    umask($old);

    // make the uploaded photo in temp folder 777 permission  -- done
    chmod($filePath, 0777);

    //write index.html  -- done
    $file = fopen($SiteVal['ContentUploadDir'].$hash."/index.html","w");
    fwrite($file,"Hi");
    fclose($file);

    //create a thumbnail image  -- page dies without errors
    createThumbs($filePath, $thumbnailPath, $width);

    //rename(move) the original image  -- rename() returns false
    rename($filePath, $renamePath);

}

function createThumbs($src, $dest, $desired_width = false, $desired_height = false)
{
    /*If no dimenstion for thumbnail given, return false */
    if (!$desired_height&&!$desired_width) return false;
    $fparts = pathinfo($src);
    $ext = strtolower($fparts['extension']);
    /* if its not an image return false */
    if (!in_array($ext,array('gif','jpg','png','jpeg'))) return false;

    /* read the source image */
    if ($ext == 'gif')
        $resource = imagecreatefromgif($src);
    else if ($ext == 'png')
        $resource = imagecreatefrompng($src);
    else if ($ext == 'jpg' || $ext == 'jpeg')
        $resource = imagecreatefromjpeg($src);

    $width  = imagesx($resource);
    $height = imagesy($resource);
    /* find the "desired height" or "desired width" of this thumbnail, relative to each other, if one of them is not given  */
    if(!$desired_height) $desired_height = floor($height*($desired_width/$width));
    if(!$desired_width)  $desired_width  = floor($width*($desired_height/$height));

    /* create a new, "virtual" image */
    $virtual_image = imagecreatetruecolor($desired_width,$desired_height);

    /* copy source image at a resized size */
    imagecopyresized($virtual_image,$resource,0,0,0,0,$desired_width,$desired_height,$width,$height);

    /* create the physical thumbnail image to its destination */
    /* Use correct function based on the desired image type from $dest thumbnail source */
    $fparts = pathinfo($dest);
    $ext = strtolower($fparts['extension']);
    /* if dest is not an image type, default to jpg */
    if (!in_array($ext,array('gif','jpg','png','jpeg'))) $ext = 'jpg';
    $dest = $fparts['dirname'].'/'.$fparts['filename'].'.'.$ext;

    if ($ext == 'gif')
        imagegif($virtual_image,$dest);
    else if ($ext == 'png')
        imagepng($virtual_image,$dest,1);
    else if ($ext == 'jpg' || $ext == 'jpeg')
        imagejpeg($virtual_image,$dest,100);

    return array(
        'width'     => $width,
        'height'    => $height,
        'new_width' => $desired_width,
        'new_height'=> $desired_height,
        'dest'      => $dest
    );
}

Solution:

Install php-gd
use copy and unlink instead of rename (just for uploaded image)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.