I have an image upload form with which I call multiple functions before uploading the file such as checking the size and dimensions, and that it is in a valid image. The code works, but calling the functions and dealing with the results seems quite cumbersome and complex.
Is there a tidier way of structuring the code?
This is what I currently have:
//Upload an image
if(checkvalidfile("img",$ext)){
if(checksize($size, 524288)) {
if(checkdimensions($tmp, 300)) {
$newfilename = renamefile($ext);
recordfileindb($brand_id, $newfilename, $mysqli);
uploadfile($tmp, $bucket, "user_docs/agency_".$agency_id."/brand_logos/", $newfilename, $s3);
header('Location: ./message.php?action=newlogo');
} else {
echo "Your image can't be bigger than 300 x 300px";
die;
}
} else {
echo "File size is too big!";
die;
}
} else {
echo "Not a valid file";
die;
}