douweng3564 2013-06-15 02:26
浏览 37
已采纳

MAX_FILE_SIZE没有给出错误?

I set a limit with a max of 10MB to uploads in my php code with

define ('MAX_FILE_SIZE', 1048576 * 10);
if ($_FILES['uploadphoto']['size'] > MAX_FILE_SIZE) { $errors[] = "Photo exceeds 10MB limit.";}

Which works fine. But I know you can put this;

<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" />

In the form so that the user knows he uploaded a file too large instantly. This works but it doesn't give the user an error message that the file was too large. What can I do to show an error message?

  • 写回答

1条回答 默认 最新

  • dsz7121 2013-06-15 03:50
    关注

    Forgot about case 2!

    switch($_FILES['uploadphoto']['error']) {
    
    case 2:
    echo 'Photo exceeds 10MB limit.';
    break;
    }
    

    Thank you @Passerby!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 wpf datagrid如何实现多层表头
  • ¥15 为啥画版图在Run DRC会出现Connect Error?可我Calibre的hostname和计算机的hostname已经设置成一样的了。
  • ¥20 网站后台使用极速模式非常的卡
  • ¥20 Keil uVision5创建project没反应
  • ¥15 mmseqs内存报错
  • ¥15 vika文档如何与obsidian同步
  • ¥15 华为手机相册里面的照片能够替换成自己想要的照片吗?
  • ¥15 陆空双模式无人机飞控设置
  • ¥15 sentaurus lithography
  • ¥100 求抖音ck号 或者提ck教程