Jump to content

resizing images


adam291086

Recommended Posts

I have a script that only half works. I got the script off a website ages ago and can no longer find it.

 

The script uploads everything fine for jpg and large pictures. When i upload any different file types the thumbnail isn't created. Any help is appreciated. This is only a snippet of code

if(isset($_POST['submit']))
{
   /*== FUNCTIONS ==*/

    function getFileExtension($str) {

        $i = strrpos($str,".");
        if (!$i) { return ""; }

        $l = strlen($str) - $i;
        $ext = substr($str,$i+1,$l);

        return $ext;

    }


$pext = getFileExtension($imgfile_name);
$pext = strtolower($pext);

if ($pext == 'jpg' || $pext == 'jpeg' || $pext == 'png' || $pext == 'PNG' || $pext == 'gif' || $pext == 'GIF'){

//big picture into file    
$pathforbig = dirname(__FILE__)."/picture";
$final1 = str_replace(" ", "_", $imgfile_name);
$newfile1 = $pathforbig . "/$final1";
  
if (!copy($imgfile,"$newfile1")) 
       {
        $message = "Error Uploading File.";
          @unlink($imgfile);
       }   



//-- RE-SIZING UPLOADED IMAGE

   
    $imgsize = GetImageSize($imgfile);
   
    if (($imgsize[0] > 100) || ($imgsize[1] > 100)) 
    {
        $tmpimg = tempnam("/tmp", "MKUP");
        system("djpeg $imgfile >$tmpimg");     
        system("pnmscale -xy 100 100 $tmpimg | cjpeg -smoo 10 -qual 50 >$imgfile");
        unlink($tmpimg);
	}

   //small image
$path = dirname(__FILE__)."/thumbnail/";
    $final_filename = str_replace(" ", "_", $imgfile_name);
    $newfile = $path . "/$final_filename"; 
    if (is_uploaded_file($imgfile))
    {
       if (!copy($imgfile,"$newfile")) 
       {
     
          $message = "Error Uploading File.";
          @unlink($imgfile);
       }
   
  else
  {

$message =  "Image Uploaded Successfully. The page will now refresh";

$refresh = "<meta http-equiv=refresh content='5; URL=http://bcyorkshire.co.uk/admin/main.php'>";

  }
     }
}


 

 

Link to comment
https://forums.phpfreaks.com/topic/90377-resizing-images/
Share on other sites

Archived

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

×
×
  • Create New...

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.