Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Thanked 0 Times in 0 Posts

    Need Some help with file functions

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


  • #2
    Regular Coder meth's Avatar
    Join Date
    Jan 2003
    Thanked 9 Times in 9 Posts
    I really dont see the point of your checkImageType function. Just changing your returned values from checkImageExtension will do the trick:

    PHP Code:

    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;
    else {

    I do Web Design, Brisbane based.
    More time spent in PHP/MySQL Web Development.
    And Search Engine Optimisation takes up the rest of it.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts