【问题标题】:How to get width and height in PHP before upload?上传前如何在PHP中获取宽度和高度?
【发布时间】:2021-05-29 17:54:50
【问题描述】:

我正在尝试在上传图像之前检查图像的宽度和高度并进行一些检查,但经过大量谷歌研究后我得出了这个,这也不起作用。

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

错误:


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

这是一些 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>

有谁知道如何在上传之前检查宽度和高度? 我已经为这个问题苦苦挣扎了 2 天。 非常感谢!

PS:使用最新版本的 XAMPP。还有 PHP 8。

【问题讨论】:

标签: php html file file-upload upload


【解决方案1】:

在上传之前,您必须使用 JavaScript。

上传后使用PHP的GD类 https://www.php.net/manual/en/book.image.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-08
    • 1970-01-01
    • 1970-01-01
    • 2012-09-16
    • 2011-11-26
    • 2013-11-18
    • 2017-09-03
    相关资源
    最近更新 更多