Whats wrong with this particular code

Discussion in 'PHP' started by Bohra, Apr 15, 2009.

  1. #1
    <?php
    $imgs = $_GET["img"];
    $cod = $imgs = $_GET["cod"];
    $id = $_GET["id"];
    $imagem = "$cod/$id/$imgs";
    $img = "";
    
    $tam = 200;
    
    $ext = @strtolower(end(explode(".", $imagem)));
    if ($ext == "jpg" || $extensao == "jpeg")
    $img = @imagecreatefromjpeg($imagem);
    else if ($ext == "png")
    $img = @imagecreatefrompng($imagem);
    else if ($ext == "gif")
    $img = @imagecreatefromgif($imagem);
    
    $ox  = imagesx($img);
    $oy = imagesy($img);
    
    $x = $ox;
    $y = $oy;
    
    if ($x >= $y) {
    if ($x > $tam) {
    $x1= (int)($x * ($tam/$x));
    $y1= (int)($y * ($tam/$x));
    }
    else {
    $x1= $x;
    $y1= $y;
    }
    }
    else {
    if ($y > $tam)
    {
    $x1= (int)($x * ($tam/$y));
    $y1= (int)($y * ($tam/$y));
    }
    else {
    $x1= $x;
    $y1= $y;
    }
    }
    $x = $x1;
    $y = $y1;
    
    $img_final = @ImageCreateTrueColor($x, $y);
    @ImageCopyResampled($img_final, $img, 0, 0, 0, 0, $x+1, $y+1, $ox, $oy);
    
    header("Content-type: image/jpeg");
    imagejpeg($img_final);
    ?>
    Code (markup):

    Warning: imagesx(): supplied argument is not a valid Image resource in /home/xxxxx/thumb.php on line 16

    Warning: imagesy(): supplied argument is not a valid Image resource in /home/xxxx/thumb.php on line 17

    Warning: Cannot modify header information - headers already sent by (output started at /home/xxx/thumb.php:16) in /home/xxx/thumb.php on line 49

    Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/xxxx/thumb.php on line 50
     
    Bohra, Apr 15, 2009 IP
  2. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #2
    Nevermind found out my mistake it was $cod = $imgs = $_GET["cod"];
     
    Bohra, Apr 16, 2009 IP
  3. CDZ

    CDZ Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Exactly that was the problem. But any way whenever you need some help, it would be a pleasure to help you out.
     
    CDZ, Apr 16, 2009 IP
  4. pipes

    pipes Prominent Member

    Messages:
    12,766
    Likes Received:
    958
    Best Answers:
    0
    Trophy Points:
    360
    #4
    Im just starting to read and learn about php recently, can i ask was it because of the lack of space between $ and cod in that $cod = $imgs = $_GET["cod"];

    Im brand new to the stuff, its all helpful to understand this better.

    Hope you both dont mind me asking.
     
    pipes, Apr 16, 2009 IP
  5. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #5
    No it was because in this code

    $cod = $imgs = $_GET["cod"];
    Code (markup):
    I Had to assign the value of $_GET["cod"]; to $cod which by mistakely i added another variable $imgs = which wasnt needed
     
    Bohra, Apr 16, 2009 IP
    pipes likes this.
  6. pipes

    pipes Prominent Member

    Messages:
    12,766
    Likes Received:
    958
    Best Answers:
    0
    Trophy Points:
    360
    #6
    Thanks very much for explaining Bohra, im glad that i asked.
     
    pipes, Apr 16, 2009 IP
  7. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #7
    No Problem Mate i guess any problem u have u can just post in this section some1 or the other does surely help out

    Regards
     
    Bohra, Apr 16, 2009 IP