php - Count the number of files selected for upload within multiple file fields -
i've wrote script user can select upload more 1 image form. i'm preventing user submitting form until of file fields have been added contain files upload.
eg:
the user has 3 file fields fill in, therefore 3 files must ready submission database.
i'm using same id on each of file upload fields. when use print_r($_files); returns me array. if browse file in first file field, , leave 2 blank, state array object [1] , [2] blank, [0] have name, type, size etc exists.
how go making sure of file fields filled in using php?
thanks in advance, rich
here efforts far:
$imgname1 = $_files['upload1']['name']; $imgtmp1 = $_files['upload1']['tmp_name']; $imgtype1 = $_files['upload1']['type']; $imgsize1 = $_files['upload1']['size']; print_r($_files); if(!$imgtmp1){ echo "<span class='error'>you need include @ least 1 image article.</span>"; exit(); } else { $filecount=($_files['upload1']['name']); // attempt count file fields filled in $cnt = $_post['cnt']; // number of file fields exist echo "<br/>"; echo count($filecount); if($cnt != $filecount){ echo "<span class='error'>you have not uploaded of files.</span>"; exit(); } // etc etc
you have incorrect upload checking. presence in $_files doesn't mean file uploaded. failed upload still create $_files entries.
you need check both presence of $_files entry, , error parameter:
if (isset($_files['upload1'])) { if ($_files['upload']['error'] === upload_err_ok) { ... file uploaded } else { ... upload failed } } else { ... no file upload attempted }
Comments
Post a Comment