Image resizing with GD Library not working (PHP)

I am trying to manipulate (scale) images with GD Library, but finally get black images. $target variable seem to not be passed to function 'resize', so imagecopyresampled isn't working properly I guess. Any ideas?

Few notes: 1. GD is enabled on server-side; 2. I have tried changing headers to header('Content-type:image/png'); 3. Image files are readable; 4. $moveResult function saves first (not resized) img file.

<?php
session_start();
require_once('db-connection.php');
// Access the $_FILES global variable for this specific file being uploaded
// and create local PHP variables from the $_FILES array of information
$fileName = $_FILES["uploaded_file"]["name"]; // The file name
$fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"]; // File in the PHP tmp folder
$fileType = $_FILES["uploaded_file"]["type"]; // The type of file it is
$fileSize = $_FILES["uploaded_file"]["size"]; // File size in bytes
$fileErrorMsg = $_FILES["uploaded_file"]["error"]; // 0 for false... and 1 for true
$kaboom = explode(".", $fileName); // Split file name into an array using the dot
$fileExt = end($kaboom); // Now target the last array element to get the file extension
// START PHP Image Upload Error Handling --------------------------------------------------
if (!$fileTmpLoc) { // if file not chosen
    $_SESSION['err1'] = "Błąd. Brak zdjęcia do przesłania";
    unset($_SESSION['imageUploaded']);
    header('Location: /edit.php');
} else if($fileSize > 2097152) { // if file size is larger than 2 Megabytes
    $_SESSION['err2'] = "Błąd. Maksymalny rozmiar zdjęcia to 2Mb";
    unset($_SESSION['imageUploaded']);
    unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
    header('Location: /edit.php');
} else if (!preg_match("/.(gif|jpg|png)$/i", $fileName) ) {
     // This condition is only if you wish to allow uploading of specific file types    
     $_SESSION['err3'] = "Błąd. Prosimy o przesłanie zdjęcia w .gif, .jpg, lub .png.";
     unset($_SESSION['imageUploaded']);
     unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
     header('Location: /edit.php');
} else if ($fileErrorMsg == 1) { // if file upload error key is equal to 1
    $_SESSION['err4'] = "Podczas przesyłania zdjęcia wystąpił nieoczekiwany błąd. Spróbuj ponownie.";
    unset($_SESSION['imageUploaded']);
    header('Location: /edit.php');
}
    // changing file name to something random
    $user = $_SESSION['id'];
    $rand = mt_rand();
    $name1 = $user.'_'.$rand;
    $folder = 'imagesResized/';
    $folder2 = 'images/';
    $newName = $name1.'.'.$fileExt;

    $newName2 = $folder.'330_'.$newName;
    $newName3 = $folder.'210_'.$newName;
    $newName4 = $folder.'115_'.$newName;
    $newName5 = $folder.'33_'.$newName;
    $newName6 = $folder2.$newName;
    //end of changing file name to something random
// END PHP Image Upload Error Handling ----------------------------------------------------
// Place it into your "uploads" folder mow using the move_uploaded_file() function
$moveResult = move_uploaded_file($fileTmpLoc, "images/$newName");
// save path to new image
 $savePath = "INSERT INTO photos (user_id, photo) "
. "VALUES('$user', '$newName6')";
$resultPath = mysqli_query($conn, $savePath); 
// end of save path to new image
// Check to make sure the move result is true before continuing
if ($moveResult != true) {
    $_SESSION['err5'] = "Nie udało się przesłać zdjęcia. Spróbuj ponownie.";
    unset($_SESSION['imageUploaded']);
    unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
}
else{
unset($_SESSION['err1']);
unset($_SESSION['err2']);
unset($_SESSION['err3']);
unset($_SESSION['err4']);
unset($_SESSION['err5']);
$_SESSION['imageUploaded'] = "Pomyślnie przesłano zdjęcie";
}
unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder

if ($moveResult != true){

function resize($target, $newcopy, $w, $h, $ext) {
    $scale_ratio = 1;
    if (($w / $h) > $scale_ratio) {
           $w = $h * $scale_ratio;
    } else {
           $h = $w / $scale_ratio;
    }
    $img = "";
    $ext = strtolower($ext);
    if ($ext == "gif"){ 
      $img = imagecreatefromgif($target);
    } else if($ext =="png"){ 
      $img = imagecreatefrompng($target);
    } else { 
      $img = imagecreatefromjpeg($target);
    }
    $tci = imagecreatetruecolor($w, $h);
    // imagecopyresampled(dst_img, src_img, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h)
    imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig);
    imagejpeg($tci, $newcopy, 80);
}

$target_file = "images/$newName";
$resized_file = "imagesResized/330_$newName";
$wmax = 330;
$hmax = 330;
resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
// save path to new image
 $savePath = "INSERT INTO photos (user_id, photo) "
. "VALUES('$user', '$newName2')";
$resultPath = mysqli_query($conn, $savePath); 
// end of save path to new image
$resized_file = "imagesResized/210_$newName";
$wmax = 210;
$hmax = 210;
resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
// save path to new image
 $savePath = "INSERT INTO photos (user_id, photo) "
. "VALUES('$user', '$newName3')";
$resultPath = mysqli_query($conn, $savePath); 
// end of save path to new image
$resized_file = "imagesResized/115_$newName";
$wmax = 115;
$hmax = 115;
resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
// save path to new image
 $savePath = "INSERT INTO photos (user_id, photo) "
. "VALUES('$user', '$newName4')";
$resultPath = mysqli_query($conn, $savePath); 
// end of save path to new image
$resized_file = "imagesResized/33_$newName";
$wmax = 33;
$hmax = 33;
resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
// save path to new image
 $savePath = "INSERT INTO photos (user_id, photo) "
. "VALUES('$user', '$newName5')";
$resultPath = mysqli_query($conn, $savePath); 
// end of save path to new image
// ----------- End Universal Image Resizing Function -----------
}
header('Location: /edit.php');
?>