Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.