Click here to Skip to main content
13,042,421 members (130,757 online)
Rate this:
Please Sign up or sign in to vote.
See more:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
        <meta name="author" content="" />
        <title>Dynamic Thumbnails</title>
        <h1>Upload A File, Man!</h1>
        <form enctype="multipart/form-data" action="<?php print $_SERVER['PHP_SELF'] ?>" method="post">
            <input type="file" name="fupload" />
            <input type="submit" value="Go!" />

    require 'config.php';
    require 'functions.php';
    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 );

and here is my function for thumb creation

<?php function createThumbnail($filename) {
        require 'config.php';
        if(preg_match('/[.](jpg)$/', $filename)) {
            $im = imagecreatefromjpeg($path_to_image_directory . $filename);
        } else if (preg_match('/[.](gif)$/', $filename)) {
            $im = imagecreatefromgif($path_to_image_directory . $filename);
        } else if (preg_match('/[.](png)$/', $filename)) {
            $im = imagecreatefrompng($path_to_image_directory . $filename);
        $ox = imagesx($im);
        $oy = imagesy($im);
       // $nx = $final_width_of_image;
       $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);
        if(!file_exists($path_to_thumbs_directory)) {
          if(!mkdir($path_to_thumbs_directory)) {
               die("There was a problem. Please try again!");
        imagejpeg($nm, $path_to_thumbs_directory . $filename);
        $tn = '<img src="' . $path_to_thumbs_directory . $filename . '" alt="image" />';
        $tn .= '<br />Congratulations. Your file has been successfully uploaded, and a      thumbnail has been created.';
        echo $tn;
    } ?>

Here is my code for creating thumbs of images
images are storing to folder but thmbs are not creating but success message is displaying that thumbs are created successfully

So,please can any one check the code and get me the error

Thanks for help in advance
Sorry if it is not clear
Posted 5-Sep-12 0:32am
Updated 5-Sep-12 0:46am
Sandeep Mewara 5-Sep-12 6:38am
This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.
enhzflep 5-Sep-12 6:57am
At a quick glance, are you sure this is what you really want to do here?
$ny = floor($oy * ($final_width_of_image / $ox));

Wouldn't that equate to:
$ny = floor($oy * ('100px' / $ox));

Use of echo or print statements to confirm your variables hold what you think they do would be a good start. Checking for errors would then be a nice 2nd step..
Manjula.g 5-Sep-12 7:02am
heh thanks for the time it is working now
i have not included $path_to_image_directory='images/';
in my function so the error is.

Now,it is working fine

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 5 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100