Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: HTML PHP
<!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 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 5-Sep-12 1:32am
Edited 5-Sep-12 1:46am
v4
Comments
Sandeep Mewara at 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 at 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 at 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
0 OriginalGriff 381
1 Sergey Alexandrovich Kryukov 265
2 Praneet Nadkar 237
3 Marcin Kozub 225
4 /\jmot 189
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 5 Sep 2012
Copyright © CodeProject, 1999-2014
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