I have a file upload code that works perfectly, but the alert in the else condition is not working just the IF alert.
Follow the code:
if(isset($_FILES['allfiles'])){//verifica o input file, caso estiver setado irá preparar as variaveis e caso o arquivo seja maior que 15mb irá mostrar erro.
$errors= array();
$file_name = $_FILES['allfiles']['name'];
$namefile = $_POST ['allfiles'];
$file_size = $_FILES['allfiles']['size'];
$file_tmp = $_FILES['allfiles']['tmp_name'];
$file_type= $_FILES['allfiles']['type'];
$ext = pathinfo($file_name, PATHINFO_EXTENSION);
$pasta1 = $_POST ['pasta1'];
$pasta2 = $_POST ['pasta2'];
if($file_size > 15097152){
$errors[]='O arquivo nao pode exceder 15mb';
}
if(empty($errors)==true){//caso não haja erro irá mover o arquivo para o diretório selecionado.
if (empty ($namefile)==true){
if (empty ($pasta1)==false){
move_uploaded_file($file_tmp,"pasta/".$ID."/pasta1/".$file_name);
}
if (empty ($pasta2) ==false){
move_uploaded_file($file_tmp,"pasta/".$ID."/pasta2/".$file_name);
}
}
if (empty ($namefile)==false){
if (empty ($pasta1)==false){
move_uploaded_file($file_tmp,"pasta/".$ID."/pasta1/".$file_name);
rename ("pasta/".$ID."/pasta1/".$file_name, "pasta/".$ID."/pasta1/".$namefile.".".$ext);
}
if (empty ($pasta2) ==false){
move_uploaded_file($file_tmp,"pasta/".$ID."/pasta2/".$file_name);
rename ("pasta/".$ID."/pasta2/".$file_name, "pasta/".$ID."/pasta2/".$namefile.".".$ext);
}
}
echo "<script>alert('Arquivo enviado com sucesso!')</script>";
}else{
echo "<script>alert('Arquivo deve ser menor que 15mb!')</script>";
}
}
OBS : I already checked if the problem was the $ errors variable, but even putting it in the $ IF file_size still does not work, I believe there is some conflict in php. I've already tested the code on another blank page and it still did not work, the only thing that happens when I try to upload a file larger than 15mb is a reload on the page, which I do not understand so far as I have no reference to a refresh on code. Does anyone have any idea what might be causing this problem?