php如何限制图片上传大小

发布于 2024-11-19 22:01:32 字数 63 浏览 3 评论 0原文

如何限制图片大小 我应该在哪里插入代码? 我可以上传图片,但只能上传并显示 4 张图片。 我能做什么来解决它?

How do I restrict the picture size
and where do I insert the code in?
I can manage to upload pictures but it only can upload and display 4 pictures.
what can I do to solve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

说好的呢 2024-11-26 22:01:33

当您使用 PHP 上传文件时,上传时可用的信息位于数组中:$_FILES['image'](图像是表单中输入的文件的名称)。该数组包含一些有用的信息:(复制自:http://php.net/ Manual/en/reserved.variables.files.php)

            [name] => MyFile.txt (comes from the browser, so treat as tainted)
        [type] => text/plain  (not sure where it gets this from - assume the browser, so treat as tainted)
        [tmp_name] => /tmp/php/php1h4j1o (could be anywhere on your system, depending on your config settings, but the user has no control, so this isn't tainted)
        [error] => UPLOAD_ERR_OK  (= 0)
        [size] => 123   (the size in bytes)

[size] 将为您提供文件大小(以字节为单位)。如果您想根据尺寸处理上传,则必须先完成上传,然后使用 PHP 函数 getimagesize 检查尺寸

When you upload files using PHP the information available while uploading is in array: $_FILES['image'] (image is the name of the file input in your form). This array contains some useful information: (copied from: http://php.net/manual/en/reserved.variables.files.php)

            [name] => MyFile.txt (comes from the browser, so treat as tainted)
        [type] => text/plain  (not sure where it gets this from - assume the browser, so treat as tainted)
        [tmp_name] => /tmp/php/php1h4j1o (could be anywhere on your system, depending on your config settings, but the user has no control, so this isn't tainted)
        [error] => UPLOAD_ERR_OK  (= 0)
        [size] => 123   (the size in bytes)

[size] would give you the filesize in bytes. If you want to deal with the upload based on it's dimensions you will have to finish the upload first and then check dimensions using PHP function: getimagesize

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文