Function to validate file extension ( PHP )
Function to validate file extension ( PHP )
function validate_extension($file_name) {
$ext_array = array(".zip",".rar",".jpg",".jpeg",".gif",".bmp");
$extension = strtolower(strrchr($file_name,"."));
$ext_count = count($ext_array);
if (!$file_name) {
return false;
} else {
if (!$ext_array) {
return true;
} else {
foreach ($ext_array as $value) {
$first_char = substr($value,0,1);
if ($first_char <> ".") {
$extensions[] = ".".strtolower($value);
} else {
$extensions[] = strtolower($value);
}
}
foreach ($extensions as $value) {
if ($value == $extension) {
$valid_extension = "TRUE";
}
}
if ($valid_extension) {
return true;
} else {
return false;
}
}
}
}
$ext_array = array(".zip",".rar",".jpg",".jpeg",".gif",".bmp");
$extension = strtolower(strrchr($file_name,"."));
$ext_count = count($ext_array);
if (!$file_name) {
return false;
} else {
if (!$ext_array) {
return true;
} else {
foreach ($ext_array as $value) {
$first_char = substr($value,0,1);
if ($first_char <> ".") {
$extensions[] = ".".strtolower($value);
} else {
$extensions[] = strtolower($value);
}
}
foreach ($extensions as $value) {
if ($value == $extension) {
$valid_extension = "TRUE";
}
}
if ($valid_extension) {
return true;
} else {
return false;
}
}
}
}
Similar topics
» Php file upload
» Set file upload limit size
» updating configuration file in browser
» Check if a file exists on a remote FTP server with PHP
» Set file upload limit size
» updating configuration file in browser
» Check if a file exists on a remote FTP server with PHP
Permissions in this forum:
You cannot reply to topics in this forum
Fri Jul 22, 2011 1:37 pm by shyamsunder
» Thousands of Free PHP Scripts Recommended
Wed May 18, 2011 10:33 am by bizboy12
» PHP form validation problem?
Wed Jan 12, 2011 1:25 pm by simy202
» string wrap
Sat Aug 02, 2008 2:06 pm by scvinodkumar
» retrieving current date rows
Tue Jul 15, 2008 3:25 am by scvinodkumar
» number in words
Tue Apr 29, 2008 3:10 pm by scvinodkumar
» Simple PHP Form Field Generator
Fri Apr 25, 2008 12:28 pm by scvinodkumar
» PHP password generator
Fri Apr 18, 2008 7:24 pm by scvinodkumar
» PHP Script to Extract Email Address from any text
Fri Apr 18, 2008 7:18 pm by scvinodkumar