0

I have a form for uploading photos in my website and use a php script to save the file. this is my php script:

$here=time();
$tmpName = $_FILES['myimage']['tmp_name'];
if($_FILES['myimage']['type']!='image/jpeg' && 
   $_FILES['myimage']['type']!='image/jpg' && 
   $_FILES['myimage']['type']!='image/png'){
       die("wrong file type");
}else{
   $target = 'photos/user='.strtolower($showusername).'&on='.$here.'.jpg';
   move_uploaded_file( $_FILES['myimage']['tmp_name'], $target);
   $query=mysql_query("INSERT INTO Pics(datetime,name,details)VALUES('$oni','$showusername','$det')")or die("unable to upload sorry");
}

can yo help me modify my script so that the image is resized to 50% before saving if it is larger than 500 kb?

Zagor23
  • 1,953
  • 12
  • 14
user2840510
  • 69
  • 2
  • 7

1 Answers1

0

Use the PHPThumb library. Very useful to work with images

require_once '../phpthumb/ThumbLib.inc.php';

$tempFile = $_FILES['myimage']['tmp_name'];

PhpThumbFactory::create($tempFile)->resizePercent(50)->save($target);
Joao Palma
  • 126
  • 5