duan205571 2014-05-05 10:23
浏览 69
已采纳

如果所有字段都为空,则在php中验证数组

I have array for uploading photos. I have to validate it for blank values.

 <input type="file" name="photos[]">
 <input type="file" name="photos[]">
 <input type="file" name="photos[]">

If a pic is uploaded in any of 3 fields, It should not throw error else if all the fields are blank, it shld throw error such as "Required at least 1 field.".

Please Note: input field photos[] are dynamically generated with jquery to upload multiple photos at a time. Please Help

  • 写回答

2条回答 默认 最新

  • doulu5717 2014-05-05 10:40
    关注

    May be this can help you to check the file upload from PHP

    if (isset($_FILES['photos'])) {
        $photos = $_FILES['photos'];
        $proceed = false;
        foreach ($photos as $photo) {
            if ($photo["error"] <= 0) {
                $proceed = true;
            }
        }
        if (!$proceed) {
            echo "Please upload at least one file";
        }
    }
    

    or you can directly use jQuery / Javascript for this before submit the form

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败