-3

I have a the following code which returns false even if I upload a file with valid extension ?

$file = JRequest::getVar('filename', null, 'files', 'array');

jimport('joomla.filesystem.file');

if(strtolower(JFile::getExt($file)) == 'pdf' || strtolower(JFile::getExt($file)) == 'gif' || strtolower(JFile::getExt($file)) == 'jpg' || strtolower(JFile::getExt($file)) == 'png') {
  // ..
}
else {
  // ..
}
Techie
  • 44,706
  • 42
  • 157
  • 243
Raaman Rai
  • 215
  • 5
  • 15

1 Answers1

1

JFile::getExt() function of joomla API returns the extension of any file, but I think there is a bug, if your file has no extension, for example Readme files which do not have any extension, in that case it should return a null, but it returns the complete filepath.

So, instead we should use this better alternative

pathinfo ($file_path,PATHINFO_EXTENSION);

Read more

Read this for eg & This too

Community
  • 1
  • 1
Techie
  • 44,706
  • 42
  • 157
  • 243
  • thanks for your kind help. well i got it working just by adding the entire code in the model. earlier i was validating it in the controller. i don't really understand the difference but its working – Raaman Rai Jan 03 '13 at 09:17