图像库将变量传递到标题位置不起作用?

时间:2014-10-23 19:29:01

标签: php html image

下面提到的代码是 localhost / uploads / gallery.php 文件。我将它包含在另一个页面中,因此它可以成为页眉和页脚的一部分,包括我的所有样式。我是通过 include('uploads / gallery.php'); 进入div的。

除标题位置外,一切正常。当我进入包含图库的页面时,“localhost / index.php?page = media”(localhost / views / media.php)。它不显示缩略图。我必须刷新页面才能看到缩略图。注意:编写代码时会生成缩略图而不刷新页面。

我对提问的顾虑是,为什么我必须刷新页面才能加载缩略图。我的标头位置没有正确传递变量。我是一个完整的菜鸟。请帮我解决一下这个。 Shukriya。

<?php
if(isset($_GET['img'])){

    if(file_exists("uploads/{$_GET['img']}")) {

        ignore_user_abort(true);

        set_time_limit(120);

       ini_set('memory_limit', '256M');

        $src_image = getimagesize("uploads/{$_GET['img']}");
        var_dump($src_image);

        if($src_image === false) {

            die("Wrong Image");

        } # Wrong File Size

        // Fixed Thumbnail Size
        $thumb_width = 144;

        $thumb_height = 144;

        $thumb_ratio = round (($thumb_width / $thumb_height), 1);

        $src_ratio = round (($src_image[0] / $src_image[1]), 1);

        if ($src_ratio > $thumb_ratio) {
            //Landescape Image dynamic width...
            $new_size = array(($src_image[0] * $thumb_height)/$src_image[1], $thumb_height);
            $new_pos = array(($new_size[0] - $thumb_width)/2,0);

        } elseif ($src_ratio < $thumb_ratio) {
            //PORTRAIT Image dynamic Height.....
            $new_size = array($thumb_width, ($src_image[1] * $thumb_width)/$src_image[0]);
            $new_pos = array(0, ($new_size[1] - $thumb_height)/2);

        } elseif($src_ratio == $thumb_ratio) {
            //Square
            $new_size = array($thumb_width, $thumb_height);
            $new_pos = array(0, 0);
        }

        if($new_size[0] < 1) $new_size[0] = 1;
        if($new_size[1] < 1) $new_size[1] = 1;

        $imgz = 'uploads/thumbs/'.$_GET['img'];

        //GETTING Variable for Source image type. to create resample
        if($src_image['mime'] === "image/jpeg"){
            $src = imagecreatefromjpeg('uploads/'.$_GET['img']);
        } elseif($src_image['mime'] === "image/png"){
            $src = imagecreatefrompng('uploads/'.$_GET['img']);
        } elseif($src_image['mime'] === "image/gif"){
            $src = imagecreatefromgif('uploads/'.$_GET['img']);
        }


        $thumb = imagecreatetruecolor($thumb_width, $thumb_height);
        imagecopyresampled($thumb, $src, 0,0, $new_pos[0], $new_pos[1], $new_size[0], $new_size[1], $src_image[0], $src_image[1]);

        //GETTING Variable for Destination thumb image type. to create resample
        if($src_image['mime'] === "image/jpeg"){
            imagejpeg($thumb, $imgz);
        } elseif($src_image['mime'] === "image/png"){
            imagepng($thumb, $imgz);
        } elseif($src_image['mime'] === "image/gif"){
            imagegif($thumb, $imgz);
        }

     header("Location: uploads/thumbs/{$_GET['img']}");


     } /* If file exists */ die();

 } // ALL SCRIPT ENDED



if(is_dir('uploads/thumbs') === false) {

    mkdir('uploads/thumbs', 0744);

} // Check & Create Directory

$images = glob('uploads/'.'*.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}', GLOB_BRACE); 

foreach($images as $image){
    $imgs = 'uploads/thumbs/'.substr($image,8);
    $nme = substr($image,8);

  if(file_exists("$imgs")){

    echo "<a href=\"#\"><img src=\"$imgs\" alt=\"$nme\" class=\"img-thumbnail\" /></a>"; //uploads/{$img} , data-toggle=\"modal\" data-target=\"#myModal\" 

     } else {

    echo "<a href=\"\"><img src=\"?page=media&img=$nme\" alt=\"$nme\" class=\"img-thumbnail\" /></a>";

  }

}

?>

0 个答案:

没有答案