Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok this is how I would do it, I haven't tested it:</p> <p>EDIT: TRY THIS</p> <pre><code>//list acceptable types $allowedExts = array("application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); //loop through uploaded files for($i=0; $i&lt;count($_FILES['file']['name']); $i++) { $file_type = $_FILES['file']['type'][$i]; if(in_array($file_type, $allowedExts)) { if ($_FILES["file"]["error"][$i] &gt; 0) { $errors[] = "Return Code: " . $_FILES["file"]["error"][$i] . "&lt;br&gt;"; }else { //if duplicate file add to array to change name if (file_exists("uuuuu/" . $_FILES["file"]["name"][$i])) { $duplicates[$i]['name'] = $_FILES['file']['name'][$i]; $duplicates[$i]['tmp_name'] = $_FILES['file']['tmp_name'][$i]; }else { //it's correct file format, a file by the same name doesn't already exist &amp; there's no file error. $eligible[$i]['tmp_name'] = $_FILES["file"]["tmp_name"][$i]; $eligible[$i]['name'] = $_FILES['file']['name'][$i]; } } }else{ $errors[] = 'Incorrect file format for '.$_FILES['file']['name'][$i]; } } if($duplicates) { array_filter($duplicates); } //we will now have an array of possible errors / files that are ok but need name changing / elligible uploads //first check for errors - which would include incorrect file types which you state you don't want any if($errors) { die( print_r($errors) ); //could make this nicer }else { //no errors so process file name changes if any then upload all files if($duplicates) { for($i=0;$i&lt;count($duplicates);$i++) { $file_name = $duplicates[$i]['name']; $random_digit=rand(0000,9999); $new_file_name=$random_digit.$file_name; $file_final = str_replace(' ', '_', $new_file_name); $path= "uuuuu/".$file_final; copy($duplicates[$i]['tmp_name'], $path); $message = "success...."; } } //upload remaining elibigle for($i=0;$i&lt;count($eligible);$i++) { move_uploaded_file($eligible[$i]['tmp_name'], "uuuuu/" . $eligible[$i]['name']); } } </code></pre> <p>NEW EDIT: THIS WORKS FOR ME..</p> <pre><code> if($_FILES) { //list acceptable types $allowedExts = array("application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); //loop through uploaded files for($i=0; $i&lt;count($_FILES['file']['name']); $i++) { $file_type = $_FILES['file']['type'][$i]; if(in_array($file_type, $allowedExts)) { if ($_FILES["file"]["error"][$i] &gt; 0) { $errors[] = "Return Code: " . $_FILES["file"]["error"][$i] . "&lt;br&gt;"; }else { //if duplicate file add to array to change name if (file_exists("uuuuu/" . $_FILES["file"]["name"][$i])) { $duplicates[$i]['name'] = $_FILES['file']['name'][$i]; $duplicates[$i]['tmp_name'] = $_FILES['file']['tmp_name'][$i]; }else { //it's correct file format, a file by the same name doesn't already exist &amp; there's no file error. $eligible[$i]['tmp_name'] = $_FILES["file"]["tmp_name"][$i]; $eligible[$i]['name'] = $_FILES['file']['name'][$i]; } } }else{ $errors[] = 'Incorrect file format for '.$_FILES['file']['name'][$i]; } } if($duplicates) { array_filter($duplicates); } //we will now have an array of possible errors / files that are ok but need name changing / elligible uploads //first check for errors - which would include incorrect file types which you state you don't want any if($errors) { die( print_r($errors) ); //could make this nicer }else { //no errors so process file name changes if any then upload all files if($duplicates) { for($i=0;$i&lt;count($duplicates);$i++) { $file_name = $duplicates[$i]['name']; $random_digit=rand(0000,9999); $new_file_name=$random_digit.$file_name; $file_final = str_replace(' ', '_', $new_file_name); $path= "uuuuu/".$file_final; move_uploaded_file($duplicates[$i]['tmp_name'], "uuuuu/" . $new_file_name); } } //upload remaining elibigle for($i=0;$i&lt;count($eligible);$i++) { move_uploaded_file($eligible[$i]['tmp_name'], "uuuuu/" . $eligible[$i]['name']); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload