I'm testing out some functionality and can't get the results I'm expecting. On a page that will process uploaded data and photos, I call a function from one of my libraries that will count the number of photos uploaded. That function ( countPhotos), first determines if no photos were uploaded, and if that's the case, returns False.
The library is an Included file and I've been reading the manual on Return and they say that if the Return comes from an Include file, control is returned to the file that calls the function. This is a bit confusing to me. Here's my script:
Code: Select all
// THIS IS THE FUNCTION CALLING "countPhotos"
// Count the number of files uploaded
$photo_num = countPhotos();
if (false) {
echo "<div id='mainContent'>
<span class='browserTable'>
<br />
<p>
You did not upload any photos.<br />
<a href='paid_bicycle_form.php'>BACK</a>
</p>
</span>
</div>";
//Display bottom wrapper
main_wrpr_bottom();
// display the footer
do_html_footer();
exit;
} else {
// Continue - the count will be used in all the photo processing functions
echo "The number of photos is ".$photo_num;
}
// THIS IS WITHIN AN INCLUDE LIBRARY FILE
function countPhotos() {
// How many photos have been uploaded?
if ($_FILES['userfile']['error'][0] == 4 && $_FILES['userfile']['error'][1] == 4 &&
$_FILES['userfile']['error'][2] == 4 && $_FILES['userfile']['error'][3] == 4 &&
$_FILES['userfile']['error'][4] == 4) {
return false;
} else {
$count_photos = 0;
foreach($_FILES['userfile']['tmp_name'] as $key => $tmp_name) {
if (is_uploaded_file($tmp_name)) {
$count_photos++;
}
}
return $count_photos;
}
}I guess what is confusing me so much is that if the function doesn't receive the False from countPhotos, why would it execute the portion of the script the outputs the message, “You did not upload any photos”. Does anybody know what I'm doing wrong here? I very much appreciate your input!
Cheers,
Rick