0

I've been trying to get PHP/GD function to work with my code, but I really don't understand how to get the codes together in single page.

I've checked many code examples but still don't understand.

How can i get this File input to resize images with aspect ratio saved depending on Height or Width only?

Deleting the original image and keeping the resized one is also a requirement.

<?php
  if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $last_name = $_POST['last_name'];
    $img = $_FILES['img']['name'];
    $imgTmp = $_FILES ['img']['tmp_name'];

    $name = mysqli_real_escape_string($dbc, $name);
    $last_name = mysqli_real_escape_string($dbc, $last_name);
    $img = mysqli_real_escape_string($dbc, $img);
    $imgTmp = mysqli_real_escape_string($dbc, $imgTmp);

    move_uploaded_file($imgTmp, "../images/$img");

    $query = "INSERT INTO database(name, last_name, image) VALUES ('$name','$last_name', '$img')";
?>

<form method="post" action="" enctype="multipart/form-data">
    <div>
        <div>
            <input type="text" name="name" placeholder="Name">
        </div>
        <div>
            <input type="text" name="last_name" placeholder="Last name">
        </div>
    </div>
    <div>
        <input type="file" name="img" value="">
    </div>
    <button name="submit" type="submit">Submit</button>
   </form>
J. 4RK
  • 62
  • 2
  • 10
  • 1
    please add the `php/gd` code, it didn't make it into the example. also the example will not compile, there is an missing closing brace. are these two snippets separate pages, the `html` and the `php`? – WEBjuju Dec 09 '16 at 15:09
  • Take a look at the intervention library http://image.intervention.io/api/resize – kyle Dec 09 '16 at 15:26
  • 1
    @WEBjuju Yes, It is the PHP and HTML in same page; I've add this code into my code after $img http://stackoverflow.com/a/27213444/7273097 But it really breaks The quality of image. – J. 4RK Dec 09 '16 at 15:33
  • @kyle Still can't figure out how and where to put these codes and Where is the function code that i should include in it. – J. 4RK Dec 09 '16 at 15:37
  • Try this solution of mine: https://stackoverflow.com/a/40324941/2430549 – HoldOffHunger Feb 21 '20 at 20:36

0 Answers0