Question

This code is uploading an image on server and saving the data in mysql. But i want the script to resize the image to a specific size. can someone help me with this?

     <?php
    error_reporting(E_ALL);
     mysql_connect("xxxxxx","xxxxx","xxxx") or 
  die("Kan geen verbinding maken met de server!");
 mysql_select_db("xxxx") or die("Kan de ingevoerde database niet vinden");

 if ($_POST){
    if (is_uploaded_file($_FILES['img']['tmp_name'])) {
        move_uploaded_file($_FILES['img']['tmp_name'], "upload/" .$_FILES['img']['name']);
    }


    $query = "INSERT INTO product (
    naam,
    id,
    titel,
    druk,
    img,
    beschrijving) 

VALUES ('".$_POST['naam']."',
        '".$_POST['id']."',
        '".$_POST['titel']."',
        '".$_POST['druk']."',
    '".$_FILES['img']['name']."',
    '".$_POST['beschrijving']."')";


  echo $query;
      mysql_query($query) or die("Kan niet invoegen.<br>". mysql_error());
     header("location:login.php");

  exit;
    }

   ?>
Was it helpful?

Solution

Before you move the uploaded file PHP Imagick::resizeImage. Do the movement of the file after re-sizing.

Here is the manual with some helpfull examples: http://php.net/manual/en/imagick.resizeimage.php

Best Regards!

(Please vote if this is helpful)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top