Talk:How to use the filesystem package
From Joomla! Documentation
The example shows a terrible coding practice: nesting ifs
if ( strtolower(JFile::getExt($filename) ) == 'jpg') {
if ( JFile::upload($src, $dest) ) {
//Redirect to a page of your choice
} else {
//Redirect and throw an error message
}
} else {
//Redirect and notify user file is not right extension
}
This sort of thing creates huge chains of if's that no knows how to look at. I think a better sample code would be:
if ( strtolower(JFile::getExt($filename) ) != 'jpg')
//Redirect and notify user file is not right extension
else if ( !JFile::upload($src, $dest) )
//Redirect and throw an error message
else
//Redirect to a page of your choice
(Ideally we'd put this in a function and return after each if, but KISS :) )