我们可以用 php 减小图像文件的大小吗?
如果图像文件大小超过了 upload_max_filesize
设置的限制,我们可以使用 PHP 减小图像文件大小吗?
例如,我的服务器上的 upload_max_filesize
只有 3MB,但上传的图像文件大小为 4MB,那么我可以通过某些 PHP 函数将 4MB 减少到 3MB 吗?
或者任何其他脚本程序可以做到这一点(我不是说使用 Photoshop 来减小文件大小)?
Can we reduce an image file size with PHP if it exceed the the limit set by upload_max_filesize
?
For instance, the upload_max_filesize
at my serve is only 3MB, but the image file size for uploading is 4MB, so can I reduce 4MB to 3MB via some PHP function?
Or any other scripting programme can do this (I don't mean using Photoshop to reduce the file size)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不,你不能。如果文件大小超过
upload_max_filesize
,PHP 将拒绝上传,因此您没有机会调整其大小。No, you can't. If the file size exceeds
upload_max_filesize
, PHP will just refuse the upload, so you have no opportunity to resize it.不 - 如果文件太大,PHP 就不可能获取该文件。
您必须使用客户端大小调整大小,这可以使用基于 Flash 或 Java 的上传器实现:
No - it's impossible for PHP to ever get hold of that file if it is too big.
You would have to use client-size resizing, which is possible using Flash- or Java-based uploaders:
阿诺是正确的。但是,如果您能够更改 upload_max_filesize,则可以增加它,然后使用 gd。
arnaud is correct. However, if you are able to change the upload_max_filesize, you could increase it and then resize any file that exceeds the max desired size using gd.
如果您可以使用
.htaccess
文件,请输入:4194288 = 4MB
If you can use
.htaccess
file, put this:4194288 = 4MB