0

I'm trying to check for the width and height of an image before uploading it and do some checking but after much Google research I came out with this, which also doesn't work.

        $tmp = $_FILES["image"]["tmp_name"];
        list($width, $height) = getimagesize($tmp); 

The error:


Fatal error: Uncaught ValueError: Path cannot be empty in C:\xampp\htdocs\CMS Blog\NewPost.php:12 Stack trace: #0 C:\xampp\htdocs\CMS Blog\NewPost.php(12): getimagesize('') #1 {main} thrown in C:\xampp\htdocs\CMS Blog\NewPost.php on line 12

Here's some of the HTML:

<form action="NewPost.php" method="POST" enctype="multipart/form-data">
                            <div class="form-group">
                                <p class="text-warning" style="margin-bottom: 7px;">Select Thumbnail:</p>
                                <div class="custom-file">
                                    <input class="custom-file-input" type="file" name="image" id="ImageInput" value="" accept="image/png, image/jpeg">
                                    <label for="ImageInput" class="custom-file-label">Upload Image</label>
                                </div>
                            </div>
</form>

Does anyone know how to check for the width and height before uploading it? I have been struggling for 2 days now with this problem. Thanks very much!

PS: Using the newest version of XAMPP. And PHP 8.

Jacob Ford
  • 4,553
  • 5
  • 27
  • 42
  • Before upload or sending request to your server it is not possible to learn it with PHP. https://stackoverflow.com/questions/8903854/check-image-width-and-height-before-upload-with-javascript – Met Br Feb 27 '21 at 17:12

1 Answers1

0

Before uploading you must use JavaScript.

After uploading use PHP's GD class https://www.php.net/manual/en/book.image.php

Aaron
  • 138
  • 1
  • 7