Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>

    <head>
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
        <meta name="author" content="" />
        <title>Dynamic Thumbnails</title>
    </head>

    <body>
        <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!" />
        </form>
</body>


</html>
    <?php

    require 'config.php';
    require 'functions.php';

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

        if(preg_match('/[.](jpg)|(gif)|(png)$/', $_FILES['fupload']['name'])) {
             $path_to_image_directory='images/';
            $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
<?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;
       $final_width_of_image='100px';
       $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);
      $path_to_thumbs_directory='thumbs/';
        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
Updated 5-Sep-12 0:46am
v4
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900