doxzrb8721 2014-07-12 08:42
浏览 48

如何正确处理服务器错误? [重复]

This question already has an answer here:

I face a big problem and would like you to help me solve one.

While uploading files on server I receive the "POST Content-Length of 323344106 bytes exceeds the limit of 5242880 bytes in Unknown on line 0" error. I know a meaning of the error, but I want to catch the error and show it to users; namely, I wanna show the error, for example, below the HTML form in order that users can understand why to receive the error.

</div>
  • 写回答

1条回答 默认 最新

  • dpp10181 2014-07-12 09:04
    关注

    This error cannot be caught as it happens before script execution. An exception is not raised, so you cannot use a try catch block.

    See: http://us2.php.net/set-error-handler

    If errors occur before the script is executed (e.g. on file uploads) the custom error handler cannot be called since it is not registered at that time.

    My recommendations are the following:

    • Set upload_max_filesize and post_max_size to be significantly greater than the maximum allowable upload size you are targeting. Any amount less than upload_max_filesize and post_max_size but greater than your allowable size can be caught and an error returned.

    • Make it clear to the user what your allowable upload size is.

    • Files greater than upload_max_filesize and post_max_size will produce that error, so set display_errors = off in production. In this cases, a blank page will be shown. Show the user what the maximum upload size is with the upload form, so that the chance of this happening is reduced.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line