Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts

    undefined call to function error

    Hello,

    This is my php code:

    PHP Code:
    case "image":
    //get all posted values
        
    $image=$_POST['picture']; $id=$_POST['id'];
        
    $make=$_POST['make']; $model=$_POST['model'];
        
        
    $uploadDir '/home/sites/test.co.uk/public_html/images/';
        
            if(isset(
    $_POST['upload'])) {
                
    $fileName $_FILES['picture']['name'];
                   
    $tmpName  $_FILES['picture']['tmp_name'];

                
    $filePath $uploadDir.$fileName;
                
    $result move_uploaded_file($tmpName$filePath);
                    if (!
    $result) {
                        
    //echo "Error uploading file";
                       
    }        
        
                    if(!
    get_magic_quotes_gpc()){
                        
    $fileName  addslashes($fileName);
                        
    $filePath  addslashes($filePath);
                    } 
                    
                
    $insert=mysql_query("UPDATE cars SET image='$image' WHERE id='$id'"$link) or die("Update Query Error ".mysql_error());
                 
            }
            if(
    $result === true) {
                
    $picture open_image($uploadDir.$fileName); 
                    if (
    $picture === false) { }
                    else{
                
                    function 
    open_image($file) {
                        
    # JPEG:
                        
    $im = @imagecreatefromjpeg($file);
                        if (
    $im !== false) { return $im; }
                
                        
    # GIF:
                        
    $im = @imagecreatefromgif($file);
                        if (
    $im !== false) { return $im; }
                
                        
    # PNG:
                        
    $im = @imagecreatefrompng($file);
                        if (
    $im !== false) { return $im; }
                                                
                                                return 
    false;
                    }
                    
    // Get original width and height
                    
    $width imagesx($image);
                    
    $height imagesy($image);
                
                    
    // Set a new width, and calculate new height
                    
    $new_width 100;
                    
    $new_height $height * ($new_width/$width);
                
                    
    // Resample
                    
    $image_resized imagecreatetruecolor($new_width$new_height);
                    
    imagecopyresampled($image_resized$image0000$new_width$new_height$width$height);
                    
                    
    imagejpeg($image_resized'../../car_images/'.$fileName);
                    
    $url="success.php";
                    
    header ("Location: $url");
                    
                    } 
            } 
    I'm getting this error :

    Fatal error: Call to undefined function: open_image() in /home/sites/test.co.uk/public_html/functions.php on line 123

    Any idea why this might be? I''m pulling my hair out and I don't understand it!!

    Thanks,

    Nicky

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Since your function is inside the "if" block, it is a conditional function, and does not exist until that "if" condition is run through. In other words, your script has not created the function yet, because it may never get created; If the "if" condition is true, that function will never exist.

    Look at Example #2 on this page of the PHP manual:

    http://us.php.net/manual/en/language.functions.php

  • Users who have thanked Fumigator for this post:

    nickyfraggle (12-09-2008)

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Ok, I see your point. I've removed all the if statements that would effect it and I'm still getting the same error.

    Any ideas?

    I'm using similar code elsewhere too and it isn't working either - without the if statements.

    Nicola
    PHP Code:

    $image
    =$_POST['picture']; $carid=$_POST['carid'];
    $make=$_POST['make']; $model=$_POST['model'];
        
    $uploadDir '/home/sites/test.co.uk/public_html/images/';
        
            
                
    $fileName $_FILES['picture']['name'];
                   
    $tmpName  $_FILES['picture']['tmp_name'];

                
    $filePath $uploadDir.$fileName;
                
    $result move_uploaded_file($tmpName$filePath);
                    if (!
    $result) {
                        
    //echo "Error uploading file";
                       
    }        
        
                    if(!
    get_magic_quotes_gpc()){
                        
    $fileName  addslashes($fileName);
                        
    $filePath  addslashes($filePath);
                    } 
                    
                
    $insert=mysql_query("UPDATE cars SET image='$image' WHERE carID='$carid'"$link) or die("Update Query Error ".mysql_error());
                 

        
    $picture open_image($uploadDir.$fileName); 
                
                    function 
    open_image($file) {
                        
    # JPEG:
                        
    $im = @imagecreatefromjpeg($file);
                        if (
    $im !== false) { return $im; }
                
                        
    # GIF:
                        
    $im = @imagecreatefromgif($file);
                        if (
    $im !== false) { return $im; }
                
                        
    # PNG:
                        
    $im = @imagecreatefrompng($file);
                        if (
    $im !== false) { return $im; }
                                                
                                                return 
    false;
                    }
                    
    // Get original width and height
                    
    $width imagesx($image);
                    
    $height imagesy($image);
                
                    
    // Set a new width, and calculate new height
                    
    $new_width 100;
                    
    $new_height $height * ($new_width/$width);
                
                    
    // Resample
                    
    $image_resized imagecreatetruecolor($new_width$new_height);
                    
    imagecopyresampled($image_resized$image0000$new_width$new_height$width$height);
                    
                    
    imagejpeg($image_resized'../../images/'.$fileName);
                    
    $url="success.php";
                    
    header ("Location: $url"); 

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    move this line:
    PHP Code:
        $picture open_image($uploadDir.$fileName); 
    after function definition:

    PHP Code:
                    function open_image($file) {
                        
    # JPEG:
                        
    $im = @imagecreatefromjpeg($file);
                        if (
    $im !== false) { return $im; }
                
                        
    # GIF:
                        
    $im = @imagecreatefromgif($file);
                        if (
    $im !== false) { return $im; }
                
                        
    # PNG:
                        
    $im = @imagecreatefrompng($file);
                        if (
    $im !== false) { return $im; }
                                                
                                                return 
    false;
                    } 
    it's a good idea to define function at the begining of the file, before you use them or to move them into a separate file which will be included where you need.

    best regards
    Last edited by oesxyl; 12-09-2008 at 08:43 PM.

  • Users who have thanked oesxyl for this post:

    nickyfraggle (12-09-2008)

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    That function must still be within an "if" block, outside the code you're showing. Just do like what oesxyl suggests; put your functions all in one place rather than "inline" like that.

  • #6
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Oh I understand now! I see where I was going wrong - blonde moment!!
    Thank you both for your help!

    Nicky


  •  

    Posting Permissions

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