php - Count number of uploaded file -


i want count number of uploaded file i'm unable error if no file had been uploaded. here code reference:

html

<input type="file" name="file[]" class="filestyle" data-buttontext="quotation 1" multiple="multiple"> 

php

$total = count($_files['file']['name']); if($total > '2'){     for($i=0; $i<$total; $i++){         $tmpfilepath = $_files['file']['tmp_name'][$i];         if($tmpfilepath != ""){            $shortname = $_files['file']['name'][$i];            $filepath = "uploads/" . date('d-m-y-h-i-s').'-'.$_files['file']['name'][$i];            if(!$msgerror && move_uploaded_file($tmpfilepath, $filepath)){                 // insert db , success msg          }     } } elseif($total < '4') {         $msgerror[] = "need upload 3 quotations";     } if(isset($msgerror)){     $msgerrorstring = implode(",",$msgerror);      header("location: pr_form.php?msgerror=".$msgerrorstring.""); } 

if user upload less 3 files, error not appear. have other validations user input. working except file validation. may know why?

first: remove '

$total > '2' should $total > 2

same total < 4


second:

it should be

count($_files) not count($_files['file']['name'])


so, in problem ..

if no file had been uploaded.

$total = count($_files); if($total > 2){     for($i=0; $i<$total; $i++){         $tmpfilepath = $_files['file']['tmp_name'][$i];         if($tmpfilepath != ""){            $shortname = $_files['file']['name'][$i];            $filepath = "uploads/" . date('d-m-y-h-i-s').'-'.$_files['file']['name'][$i];            if(!$msgerror && move_uploaded_file($tmpfilepath, $filepath)){                 // insert db , success msg          }     } } elseif($total < 4 && $total > 0) {         $msgerror = "need upload 3 quotations";     } elseif($total === 0){ //this condition     $msgerror = "no chosen file.";  } if(isset($msgerror)){     header("location: pr_form.php?msgerror=".$msgerror.""); } 

and in pr_form.php, should have line..

<?php     echo $_get['msgerror']; ?> 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -