How does this Switch statement know which case to execute? (PHP/MySQL)
- by ggfan
Here is a code form a PHP+MySQL book I am reading and I am having trouble understanding this code. This code is about checking a file uploaded into a database. (Please excuse any spelling errors if any, I was typing it in)
Q1: How does it know which case to echo? In the whole code, there is no mention of each case.
Q2: Why do they skip case 5?! Or does it not matter which numbers you use(so I can have case 1, case 18, case 2?)
if($_FILES['userfile']['error']>0)
{
echo 'Problem: ';
switch($_FILES['userfile']['error'])
{
case 1: echo 'File exceeded upload_max_filesize';
break;
case 2: echo 'File exceeded max_file_size';
break;
case 3: echo 'File only partially uploaded';
break;
case 4: echo 'No file uploaded';
break;
case 6: echo 'Cannot upload file: no temp directory specified';
break;
case 7: echo 'Upload failed: Cannot write to disk';
break;
}
exit;
}