Is this correct?

ive tried turning a script into a function but im not sure if ive done it correctly. could someone advise me if ive gone wrong please.

<?php
function thumbnail($image, $maxWidth, $maxHeight) {    
    $pinfo        = pathinfo($image);
    $tmb_name     = $pinfo['dirname'].'/thumbs/'.$pinfo['filename'].'_tmb.'.$pinfo['extension'];
$imageviewed = $pinfo['dirname'].'/viewed/'.$pinfo['filename'].'_viewed.'.$pinfo['extension'];

    
    switch($pinfo['extension']) :
        case "jpg" :
        case "jpeg" : 
            $fileType = "jpeg";
            $imageCreateFunction = "imagecreatefromjpeg";
            $imageOutputFunction = "imagejpeg";
        break;
        case "png" :
            $fileType = "png";
            $imageCreateFunction = "imagecreatefrompng";
            $imageOutputFunction = "imagepng";
        break;
        case "gif" :
            $fileType = "gif";
            $imageCreateFunction = "imagecreatefromgif";
            $imageOutputFunction = "imagegif";
        break;
    endswitch;
    
    list($originalWidth, $originalHeight) = getimagesize($image);
    
    $x_ratio = $maxWidth / $originalWidth;
    $y_ratio = $maxHeight / $originalHeight;
    
    // check that the new width and height aren't bigger than the original values.
    // the new values are higher than the original, don't resize or we'll lose quality
    if (($originalWidth <= $maxWidth) && ($originalHeight <= $maxHeight)) {
        $newWidth = $originalWidth;
        $newHeight = $originalHeight;
    } else if (($x_ratio * $originalHeight) < $maxHeight) {
        $newHeight = ceil($x_ratio * $originalHeight);
        $newWidth = $maxWidth;
    } else {
        $newWidth = ceil($y_ratio * $originalWidth);
        $newHeight = $maxHeight;
    }
    
    $src = $imageCreateFunction($image);
    $dst = imagecreatetruecolor($newWidth, $newHeight);

    // Resample
    imagecopyresampled($dst, $src, 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight);
    
    // Save image
    $imageOutputFunction($dst, $tmb_name, $imageviewed);
    
    imagedestroy($src);
    imagedestroy($dst);
    
    return true;
}
?> 

and when i call it in my upload file is this correct aswell?

&lt;?php
 
 $max_size=5*1024*1024;
 
 // Check if a file has been uploaded
if(isset($_FILES['uploaded_file']) && preg_match("/image\\/jpeg|image\\/jpg/i",$_FILES['uploaded_file']['type']) && $_FILES['uploaded_file']['size']&lt;= $max_size)
{
     // Make sure the file was sent without errors
     if($_FILES['uploaded_file']['error'] == 0)
     {
        $target_path = "images/";
        $target_path = $target_path . basename( $_FILES['uploaded_file']['name']);     
        
        if(!file_exists($target_path)){

    if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target_path))
        {
            
            function thumbnail($maxheight,$maxwidth,$image)
{
   $maxheight=150;
   $maxwidth=100;
   $image = $target_path;
}
function thumbnail($maxheight,$maxwidth,$image)
{
   $maxheight=550;
   $maxwidth=600;
   $image = $target_path;
}

            
            echo "The file ".  basename($_FILES['uploaded_file']['name']). " has been uploaded";
                                     
            $dbLink = new mysqli('localhost', 'root', '', 'gallery');
             if(mysqli_connect_errno()) {
            die("MySQL connection failed: ". mysqli_connect_error());
                                        }             
         
              // Gather all required data
              $name = $dbLink-&gt;real_escape_string($_FILES['uploaded_file']['name']);
              $mime = $dbLink-&gt;real_escape_string($_FILES['uploaded_file']['type']);
              $size = intval($_FILES['uploaded_file']['size']);
              $image_path = $dbLink-&gt;real_escape_string($target_path);
              $gallery_type = $dbLink-&gt;real_escape_string($_POST['gallery_type']);
             $desc = $dbLink-&gt;real_escape_string($_POST['desc']);
             $image_path = $dbLink-&gt;real_escape_string($target_path);
             $tmb_name = $dbLink-&gt;real_escape_string($tmb_name);
             
             //query to insert the data i had gathered into the database
             $query = "INSERT INTO `images` (`name`, `size`, `created`, `image_path`, `gallery_type_id`, `desc`, `thumbnail_path` )
             VALUES ('{$name}', {$size}, NOW(), '{$image_path}', '{$gallery_type}', '{$desc}', '{$tmb_name}')";
             
             //executes the query
             $dbLink-&gt;query($query);
        }
    }
      
    else 
         {
            echo 'A file with the same name exists please change the file name and try again';
          }
}
  
  else
          {
      echo 'A file was not sent';
        }
}

else
          {
      echo 'The file is too large';
        }
        
 // Echo a link back to the main page
 echo '&lt;p&gt;Click &lt;a href="member-index.php"&gt;here&lt;/a&gt; to go back&lt;/p&gt;'; 
 ?&gt;

At least you fail to call your function properly.
It is called exactly as any other functions. Without curly braces.

should i change this:

           function thumbnail($maxheight,$maxwidth,$image)

{

   $maxheight=150;

   $maxwidth=100;

   $image = $target_path;

}

function thumbnail($maxheight,$maxwidth,$image)

{

   $maxheight=550;

   $maxwidth=600;

   $image = $target_path;

}

to:

$image = $target_path;
$maxheight=;
$maxwidth=;
$result=$thumbnail($maxheight, $maxwidth,$image);

you should read manual entry on how to use functions.
http://www.php.net/manual/en/language.functions.php
if you please

so my code in my upload form should look like this:

          
function thumbnail($maxheight,$maxwidth,$image)

{

   $maxheight=150;

   $maxwidth=100;

   $image = $target_path;

   $result=$thumbnail($maxheight, $maxwidth, $image); 

}

function thumbnail($maxheight,$maxwidth, $image)

{

   $maxheight=550;

   $maxwidth=600;

   $image = $target_path;

   $result=$thumbnail($maxheight, $maxwidth, $image); 

} 

A far away from this.
arguments order must be same and function call must be one line, not 5

okay. im gonna take another attempt:


function thumbnail($maxheight=100,$maxwidth=150,$image=target_path)



{

   $result=$thumbnail($maxheight, $maxwidth, $image); 

} 



function thumbnail($maxheight=500,$maxwidth=650, $image=target_path)



{

   $result=$thumbnail($maxheight, $maxwidth, $image); 

} 

Tell me please.
When you call imagecreatetruecolor() function in your code, why don’t you do it in such fancy way?

im using the code i was given and im trying to modifiy it to fit my website. but am failing very badly at functions