Need Some help with file functions
Posted: Mon Feb 05, 2007 10:33 pm
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I have a function that takes in a file. What I want to is print "Success" if the extension is correct and print "fail" if it is not an acceptable extension. I have written two functions. The checkImageExtension works fine. Not sure if it is missing something. However checkImageType($file) does not work at present. It is supposed to take an uploaded file and get the filename as a string. I have been testing using a local file. Can anyone help me?Code: Select all
function checkImageExtension($name) {
// List of all acceptable extensions
$array_of_extensions = array("jpg" , "jpeg" , "bmp" , "gif" , "png");
$partitioned_image_src = explode("." , $aStr_image_src);
// Obtains the file's extension by getting the last partition of the exploded string
$image_extension = $partitioned_image_src[count($partitioned_image_src) - 1];
if (in_array($image_extension , $array_of_extensions)) {
// Renames the string to a form acceptable for linux
$aStr_image_src = str_replace(" " , "_" , $aStr_image_src);
$this->str_image_src = $aStr_image_src;
return true;
}
else {
return false;
}
function checkImageType($file) {
$filename = basename($file);
if (checkImageExtension($filename)) {
return "Success";
}
else {
return "Failed";
}
}feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]