please help me with server side validation of upload files.
I my form have 4 inputs for upload files. I need help with multi condition for this 4 inputs. First examle of validation works but only for 1 file. Second example of validation 4 files dont work.
Please help me.
<input type="file" name="orderfile1" id="orderfile1">
<input type="file" name="orderfile2" id="orderfile2">
<input type="file" name="orderfile3" id="orderfile3">
<input type="file" name="orderfile4" id="orderfile4">
//example of file validation WORKS!!!!!
//validate file uploads
if(isset($_FILES['orderfile1'])) {
$maxsize = 5242880;
if ($_FILES['orderfile1']['size'] > $maxsize) {
$errors[] = "Max file size 5MB";
}
// Detect allowed file extentions
$valid_file_extensions = array(".jpg", ".jpeg", ".png", ".zip", ".rar");
$file_extension = strrchr($_FILES["orderfile1"]["name"], ".");
if (!in_array($file_extension, $valid_file_extensions)) {
$errors[] = "Only file extension jpeg, png zip rar";
}
}
//example of 4 files validation DONT WORK!!!!
//validate files uploads
if(isset($_FILES['orderfile1'] || $_FILES['orderfile2'] || $_FILES['orderfile3'] || $_FILES['orderfile4'] )) {
$maxsize = 5242880;
if ($_FILES['orderfile1']['size'] > $maxsize || $_FILES['orderfile2']['size'] > $maxsize || $_FILES['orderfile3']['size'] > $maxsize || $_FILES['orderfile4']['size'] > $maxsize) {
$errors[] = "Max file size 5MB";
}
// Detect allowed file extentions
$valid_file_extensions = array(".jpg", ".jpeg", ".png", ".zip", ".rar");
$file_extension = strrchr($_FILES["orderfile1"]["name"], "." || $_FILES["orderfile2"]["name"], "." || $_FILES["orderfile4"]["name"], "." || $_FILES["orderfile4"]["name"], "." );
if (!in_array($file_extension, $valid_file_extensions)) {
$errors[] = "Only file extension jpeg, png zip rar";
}
}
You're going to want to use a loop on
$_FILES
.