...

View Full Version : Need Some help with file functions



j83folino
02-06-2007, 04:22 AM
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?

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";
}

}

meth
02-06-2007, 01:38 PM
I really dont see the point of your checkImageType function. Just changing your returned values from checkImageExtension will do the trick:




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 'Success';
}
else {
return 'Failed';
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum