使用图像拇指创建图像的问题 [英] problem with thumb creation of images using images

查看:76
本文介绍了使用图像拇指创建图像的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<!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;
    } ?>




这是我创建图像缩略图的代码
图像存储到文件夹中,但未创建thmb,但显示成功创建拇指的成功消息

因此,任何人都可以检查代码并得到错误信息

感谢您的提前帮助
很抱歉,如果不清楚的话




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

推荐答案

_SERVER ['PHP_SELF']吗?>" 方法 =" > < 输入 =" 名称 fupload" / > < 输入 =" 提交" 开始!" / > < /form > < /body > < /html > <? php 需要 ' config.php'; 需要 ' functions.php'; if(isset(
_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'])) { span> if(preg_match('/[.](jpg)|(gif)|(png)
_FILES['fupload'])) { if(preg_match('/[.](jpg)|(gif)|(png)


/',
/',


这篇关于使用图像拇指创建图像的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆