Jump to content

Archived

This topic is now archived and is closed to further replies.

supanoob

Uploading Images

Recommended Posts

The Below code is what i am using to upload and resize images. now i have tried uploading 2 images one of them was 300 x 300 and another was 200 x 200 and neither uploaded it cam up with an error saying it was divsion by 0 :S can anyone see why?

[code]$uploaddir = "/public_html/player_images/";
   

    $pext = getFileExtension($imgfile_name);
    $pext = strtolower($pext);
    if (($pext != "jpg")  && ($pext != "jpeg"))
    {
        print "<h1>ERROR</h1>Image Extension Unknown.<br>";
        print "<p>Please upload only a JPEG image with the extension .jpg or .jpeg ONLY<br><br>";
        print "The file you uploaded had the following extension: $pext</p>\n";

     
        unlink($imgfile);
        exit();
    }




 
    $imgsize = GetImageSize($imgfile);


    if (($imgsize[0] > 200) || ($imgsize[1] > 200))
    {

        $tmpimg = tempnam("/tmp", "MKUP");


            1. decompress jpeg image to pnm file (a raw image type)
            2. scale pnm image
            3. compress pnm file to jpeg image

       
 
        system("djpeg $imgfile >$tmpimg");
       


        system("pnmscale -xy 200 200 $tmpimg | cjpeg -smoo 10 -qual 50 >$imgfile");

 
        unlink($tmpimg);

    }


    $final_filename = str_replace(" ", "_", $imgfile_name);
    $newfile = $uploaddir/$final_filename;
   
 
    if (is_uploaded_file($imgfile))
    {

      if (!copy($imgfile,"$newfile"))
      {

          print "Error Uploading File.";
          exit();
      }
    }


    unlink($imgfile);

   
    echo "<img src=\"/public_html/player_images/$final_filename\">";
[/code]

Share this post


Link to post
Share on other sites
heres an example how to resize an image ok.

gd must be enabled in the php.ini


[code]

<?php

// Load image
$image = open_image('flower.jpg');
if ($image === false) { die ('Unable to open image'); }

// Get original width and height
$width = imagesx($image);
$height = imagesy($image);

// New width and height
$new_width = 150;
$new_height = 100;

// Resample
$image_resized = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// Display resized image
header('Content-type: image/jpeg');
imagejpeg($image_resized);
die();

?>
[/code]

Share this post


Link to post
Share on other sites
so where in my code would that go? the code i used was an example off of a website along with the functions off of php.net

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.