0
I have a perfectly functioning file upload code, but Alert in Else condition is not only working IF Alert.
Follows 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 variable $errors but even putting in the IF of $file_size still does not work, I believe there is some conflict in php. I have already tested the code on another blank page and it hasn’t worked yet, the only thing that happens when I try to upload a file bigger than 15mb is a Reload on the page, which so far I don’t understand because I have no reference to a refresh in the code. Does anyone have any idea what might be causing this problem?
The problem is not clear, especially when you say that "is working perfectly, but does not work". You apparently have two alerts: one on
if
, another in theelse
. The alert ofif
works, but ofelse
No? You are aware that only one will run at a time, right? If so, in which situation exactly does it not work? And can you improve code indentation? It’s really hard to understand when aif
begins and ends...– Woss
Exactly. Else’s Alert does not work, this Else belongs to the IF in which the condition is the empty $errors variable, where it only receives a value if the file is greater than 15 Mb, the file upload does not also occur what is right, but I would like a warning that this did not occur and I am not able to solve it in any way.
– Wel
Inserts an echo "test";Exit; into your Else and see if it appears. Sometimes the problem isn’t Alert, maybe it’s not entering Else.
– David Alves
He hasn’t returned anything either. but the problem is not in Else exactly, but in something else because it had put the script inside if($file_size > 15097152)? } and also didn’t work, I believe there is something related to trying to upload large files. maybe an overload?
– Wel
See in your php.ini how the body limit size of a request is, it must be less than 15mb, then it won’t even execute the code. Are the options post_max_size and upload_max_filesize
– Renato Diniz
I changed both to 50 and now I can not even load the page, would have some value ideal to put?
– Wel
What value was before? The default value is 20M. You need to restart the server as well to take effect.
– Renato Diniz
yes, after restarting the server I could not more. I will test with 20
– Wel
Now the server is not even starting, I don’t see sense, I put the post_max_size=20 and upload_max_filesize=20M
– Wel
I made a reboot and now it’s back to the problem of not loading the page.
– Wel
Solved by adding M to post_max_size=20M
– Wel
Problem solved, if you can answer the question to end the post
– Wel