It's a little bit difficult explain my problem.. Well, I'm creating a Upload File which the user can save just files .txt, .pdf or .doc, but there's a some files as a photo that return a array( $_FILES) empty and a other photo whose size is equal to the previous photo, return two error message the way correct..
Please, Is it my logic is wrong?
<?php
if(isset($_FILES['file']['name'])){
$valid_file = true;
//Errors Messages
$messageError = array();
//Types
$allowTypes = array('text/plain','application/msword','application/pdf');
$folder = 'C:\wamp\www\uploadtest\files/';
$path = $folder.basename($_FILES['file']['name']);
if(!$_FILES['file']['error'])
{
//Check Types
if(!in_array($_FILES['file']['type'], $allowTypes)){
$valid_file = false;
$messageError[] = 'File type not allowed';
}
//Check Size
if($_FILES['file']['size'] > (1024000))
{
$valid_file = false;
$messageError[] = "Oops! can't be larger than 1 MB";
}
//Upload Process
if($valid_file){
if(move_uploaded_file($_FILES['file']['tmp_name'],$path)){
echo "Sent!";
}else{
echo "Error to send!";
}
}
}else{
echo 'Ooops! '.$_FILES['file']['error'];
}
}else{
$messageError[] = "Please, Select a File!";
}
if(isset($messageError) or !empty($messageError)){
foreach ($messageError as $me) {
echo $me.'<br>';
}
}
?>