Hey im sort of new to php. Im a little lost in this script that ive been making. This is an upload script which has two file upload fields. I also run checks for file size and file existance. THE PROBLEM IS if i dont choose to upload one or both of the files than i get my error:
die("The file: <b>$file1</b> has the same name as another file on our server. Please rename your file and re-submit.");
Here is my code:
//Define variables for the names of each file to be uploaded from the myfiles array.
$file1 = $FILES['myfiles']['name'][0];
$file2 = $FILES['myfiles']['name'][1];
//Define variables for each files size
$file1size = $FILES['myfiles']['size'][0];
$file2size = $FILES['myfiles']['size'][1];
//Numer of upload fields i want
$numoffile = 2;
//The max file size for uploads
$maximagefilesize=1024000;
$maxavfilesize=8192000;
// upload directory
$file_dir = "upload/";
if ($_POST) {
$results = mysql_query( $query );
mysql_close();
if ($file1size > $maximagefilesize) {
die("The file: <b>$file1</b> is too large. The maximum allowd IMAGE file size is 1mb.");
}else{
if ($file2size > $maxavfilesize) {
die("The file: <b>$file2</b> is too large. The maximum allowd AUDIO/VIDEO file size is 8mb.");
}else{
//Check if file names exist for the first upload file.
if(file_exists($file_dir.$file1)) {
die("The file: <b>$file1</b> has the same name as another file on our server. Please rename your file and re-submit.");
}else{
//Check if file names exist for second upload file.
if(file_exists($file_dir.$file2)) {
die("The file: <b>$file2</b> has the same name as another file on our server. Please rename your file and re-submit.");
}else{
for ($i=0;$i<$numoffile;$i++) {
if (trim($FILES['myfiles']['name'][$i])!="") {
$newfile = $file_dir.$FILES['myfiles']['name'][$i];
move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $newfile);
$j++;
}
}
}
}
}
}
}