0

I have a function that returns either a value into a variable if it is successful or it returns an errors array. see part of it below.

function uploadEmploymentDoc($var, $var2){

$ERROR = array();

if(empty($_FILES['file']['tmp_name'])){
$ERROR[] = "You must upload a file!";
}

//find the extensions
$doctypeq = mysql_query("SELECT * FROM `DocType` WHERE `DocMimeType` = '$fileType'");
$doctype = mysql_fetch_array($doctypeq);
$docnum = mysql_num_rows($doctypeq);
if($docnum == 0){
$ERROR[] = "Unsupported file type"; 
}

if(empty($ERROR)){
// run my code
return $var;
} else{
return $ERROR;
}

then when I run my code

$result =  uploadEmploymentDoc(1, 2);

if($result !=array()){
// run code
} else {
   foreach($result as $er){
   echo $er."<br>";
   }
}

Now my question is this. Why is my function running my code and not showing me an error when I upload an unsupported document type. Am I defining my foreach loop correctly? For some reason I cant get my errors back.

4

2 に答える 2

3

あなたはこのように書くべきです-

if(is_array($result)){
   foreach($result as $er){
    echo $er."<br>";
   }
} else {
  //your code for handling error
}

詳細情報を取得できます: http://us2.php.net/is_array

于 2013-11-06T13:53:37.577 に答える