2016-04-13 30 views
-3

我需要圖像尺寸幫助,我不知道如何把在我需要把調整圖片大小150x130

<?php 

if (isset($_POST['newcover'])) { 

    ////GET image uploading settings 
    $select_upload_options = mysql_query("SELECT * FROM covers_submit_options"); 
    $uop = mysql_fetch_assoc($select_upload_options); 

    $poster = $uop['cover_who_post']; 
    $approve = $uop['cover_approve']; 
    $server = $uop['cover_server']; 
    $default_user = $uop['cover_default_user']; 


    $cover_title = $_POST['title']; 
    $cover_desc = $_POST['desc']; 
    $cover_desc2 = $_POST['desc2']; 
    $cover_date = $_POST['date']; 
    $cover_tags = $_POST['tags']; 
    $cover_okvir = $_POST['okvir']; 
    $cover_velicina = $_POST['velicina']; 
    $cover_image2 = $_POST['image2']; 

    $cover_category = $_POST['huge']; 
    if ($poster != 'user' && $_SESSION['userid'] == '') { 
     $poster_user = $default_user; 
    } else { 
     $poster_user = $_SESSION['userid']; 
    } 


    if ($cover_title == '') { 
     $post_error = '<div class="alert alert-danger"><h3>Unesite Ime i Prezme</h3></div>'; 
    } elseif ($cover_category == '') { 
     $post_error = '<div class="alert alert-danger"><h3>Izaberite Grad ii Općinu</h3></div>'; 
    } elseif ($cover_date == '') { 
     $post_error = '<div class="alert alert-danger"><h3>Unesite Datum-Godište Npr. 1965-2016</h3></div>'; 
    } elseif ($cover_okvir == '') { 
     $post_error = '<div class="alert alert-danger"><h3>Izaberite Izgled Osmrtnice</h3></div>'; 
    } elseif ($poster_user == '') { 
     $poster_user = '1'; 
    } elseif ($_FILES['photo']['size'] == '1') { 
     $post_error = '<div class="alert alert-danger"><h3>Please Select Image</h3></div>'; 
    } else { 
     $post_error = ''; 
    } 


    if ($post_error == '') { 
     if ($server == 'amazon') { 
      ////////UPLOAD TO AMAZON///////////////////// 
      include('includes/amazonUpload.php'); 

      ////////UPLOAD TO AMAZON///////////////////// 
     } else { 
      ////////////REGULAR UPLOADER TO SERVER///////// 

      list($file, $error) = upload('photo', 'images/covers/', 'jpg,jpeg,gif,png'); 

      list($width, $height, $type, $attr) = ('images/covers/' . $file); 
      ////////////Da bi upload slike mogao da radi uklonio sam dio koda orginal kod je ovaj dolje getimagesize prije zagrade images/covers ///////// 


      if ($width < 0 || $height < 0) { 
       $post_error = "<div class='alert alert-danger'><h3>The Cover is Small<br>Please note that the Minimum allowed hight is 300px and Minimum Width is 800px </h3></div>"; 
       unlink('images/covers/' . $file); 
      } else { 
       $image = 'images/covers/' . $file; 
      } 
      ////////////REGULAR UPLOADER TO SERVER///////// 
      $error = $post_error; 
     } 

     ////Store Into Database 
     if (!$error) { 

      $string = $slug; 

      if (strlen($string) != mb_strlen($string, 'utf-8')) { 
       $slug = date("M-D-His"); 
      } else { 

       $slug = preg_replace("/[^a-zA-Z0-9_\-]/", '', $cover_title); 
       //$slug = preg_replace('/\s+/', '-', $cover_title); 
       $slug = strtolower($slug); 
      } 
      $is_slug_exists = mysql_query("SELECT * FROM covers_posts WHERE post_slug = '$slug' "); 
      $slug_exsits = mysql_num_rows($is_slug_exists); 

      if ($slug_exsits != '0') { 
       $slug = $slug . '-' . date('sy'); 
      } else { 
       $slug = $slug; 
      } 


      $cover_datum = date("d-m-Y"); 
      $insert = mysql_query("INSERT INTO covers_posts VALUES ('', 
       '$cover_title', 
        '$cover_desc', 
        '$cover_desc2', 
        '$cover_date', 
        '$cover_tags', 
         '$cover_okvir', 
         '$cover_velicina', 
        '$slug', 
        '$image', 
        '$cover_image2', 
        '$cover_category', 
        '1', 
        '$poster_user', 
        '$approve', 
        '0', 
        '0', 
        '0', 
        '$cover_datum' 
        ) "); 


      order_badge($poster_user); 



      $post_error = '<div class="alert alert-success"><h3>Uspješno Ste Dodali Osmrtnicu , Prebacit će vas za 5 sekundi<br> 
       Ukolko ste zastali <a href="osmrtnica-' . $slug . '.html">Kliknite Ovde</a> 
       </h3></div>'; 
      $redir = 'osmrtnica-' . $slug . '.html'; 
      redirect($redir, '5'); 
     } else { 
      $post_error = '<div class="alert alert-danger"><h3>' . $error . '</h3></div>'; 
     } 
    } else { 
     $post_error = $post_error; 
    } 
    $smarty->assign('UploadResult', $post_error); 
} 
+0

歡迎來到SO。 請閱讀[我可以問哪些主題](http://stackoverflow.com/help/on-topic) 和[如何提出一個好問題](http://stackoverflow.com/help/how-to - 問) 和[完美的問題](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) SO是**不是免費的編碼或教程服務* *你必須表明你已經努力解決你自己的問題。 – RiggsFolly

+0

從這裏開始[它被稱爲手冊,噓,這是一個祕密,不告訴任何人你現在知道它在哪裏](http://php.net/manual/en/book.image.php) – RiggsFolly

+1

**停止* * usinf棄用'mysql_ *'API。使用'mysqli_ *'或'PDO' – Jens

回答

0

好,我知道這是舊的劇本,我在mysqli的連接以後更改。 我閱讀有關上傳和調整圖像大小的手冊現在它調整大小圖像,但所有圖像都是黑色的

elseif ($cover_okvir == '') { 
     $post_error = '<div class="alert alert-danger"><h3>Izaberite Izgled Osmrtnice</h3></div>'; 
    } 
    elseif ($poster_user == '') { 
     $poster_user = '1'; 
    }else{ 

      ////////////REGULAR UPLOADER TO SERVER///////// 

      list($file,$error) = upload('photo','images/covers/','jpg,jpeg,gif,png'); 

      list($width, $height, $type, $attr) = getimagesize('images/covers/'.$file); 

        $width = 140; 
        $height = 150; 
      ////////////REGULAR UPLOADER TO SERVER///////// 

     $src = imagecreatefromstring('images/covers/'.$file); 
$dst = imagecreatetruecolor($width,$height); 
imagecopyresampled($dst,$src,0,0,0,0,$width,$height); 
imagedestroy($src); 
imagepng($dst,'images/covers/'.$file); // adjust format as needed 
imagedestroy($dst); 

} 
     $image = 'images/covers/'.$file; 
    enter code here