如何更改分配内存的允许量? [英] How to change the allowed amout of allocated memory?

查看:101
本文介绍了如何更改分配内存的允许量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

致命错误:在第62行的/ mounted-storage / home20a / sub001 / sc20063-GJYD / [...]中,允许的内存大小为33554432字节(试图分配40000字节)

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 40000 bytes) in /mounted-storage/home20a/sub001/sc20063-GJYD/[...] on line 62

看起来PHP脚本只允许我为内存分配32 MB?这是使用示例图像来测试用户尝试上传时会发生什么情况巨大的图片。

It looks like the PHP-script only allowes me to allocate 32 MB to the memory? This was with an example image to test what would happen if a user tries to upload a huge picture.

我的问题是:我如何预测会发生这种情况,然后提醒用户图像太大而不是返回此错误?我测试了一段时间,但我想我尝试了try-catch和@,但是他们都失败了,因为这是一个致命的错误。示例图像的大小仅为1 kB,因此无法检查该值。

My question is: How can i predict that this will happen, and then alert the user that the image was too big instead of returning this error? Its a while since I tested it, but I think I tried both try-catch and @, but they both failed since this is a fatal error. The size of the example image is only 1 kB, so it won't work checking that value.

我想我解决了我自己的问题,我可以检查图像的$ width和$ height,然后通知用户图像是否太大,但我有另一个问题:如何更改分配内存的允许值?我假设我的用户会尝试发布许多高分辨率的图像。我试过 ini_set(memory_limit,$ bignumber),但它无效。

I think I solved my own problem, I can check the $width and $height of the image, and then notify the user if the image is too big, but I have another question: How do I change the allowed amout of allocated memory? I assume that my users will try to post many high-resolutioned images. I have tried ini_set("memory_limit", $bignumber), but it isn't working.

推荐答案

要更改 memory_limit ,您必须编辑 memory_limit 指令 - 它可以在你的如果您不希望修改对整个服务器有效,而且只针对一个网站,那么Apache的VirtualHost也是如此。

To change the memory_limit, you have to edit the memory_limit directive in your php.ini file -- it can be done in your Apache's VirtualHost, too, if you don't want the modification to be effective for your whole server, but only for one website.

但是你可能并不总是这样做 - - 您需要成为服务器的管理员......

But you might not always do that -- you need to be administrator of your server...

BTW,你可以看看如何更改配置设置

BTW, you can take a look at How to change configuration settings.



另一种可能性可能是使用imagemagick及其转换可执行文件,使用其中一个程序执行功能。这样,PHP的图像大小就不会重新调整。


Another possibility might be to use imagemagick, and its convert executable, using one of the Program execution Functions. This way, the resizing of your image wouldn't be done by PHP.

但是,这里,这意味着你依赖外部程序......

But, here, it means you depend on an external program...

这篇关于如何更改分配内存的允许量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆