I wrote some code to upload an image to a server. Now I wanted to add a function "imageresize" wich resizes the image to a predefinded height and width. When I run it I get a fatal error
what I've tried: I found a simple piece of code on the internet witch works and tried the same stucture in my script
<?php
function voegGebruikerToe ($naam, $Ww, $WwConfirm, $sqlInsert, $nameImage, $naamDiv) {
if(!empty($naam) and !empty($Ww) and !empty($WwConfirm)){
if ($Ww == $WwConfirm) {
$passHash = password_hash($Ww, PASSWORD_DEFAULT); // Creates a password hash
$sql1 = "INSERT INTO users (username, password) VALUES ('$naam', '$passHash')";
if ($sqlInsert->query($sql1) === TRUE) { //insert invevoerde data to database
echo "ok";
} else {
}
} else {
echo "your passwords doesn't match";
}
} else{
echo "Please enter all the fields.";
}
$file = $_FILES[$naamDiv]['tmp_name'];
$sourceProperties = getimagesize($file);
$fileNewName = $nameImage;
$folderPath = "/var/www/";
$ext = pathinfo($_FILES[$naamDiv]['name'], PATHINFO_EXTENSION);
$imageType = $sourceProperties[2];
$imageFileType = strtolower(pathinfo($_FILES[$naamDiv]['name'],PATHINFO_EXTENSION));
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed. <br>";
} else {
switch ($imageType) {
case IMAGETYPE_PNG:
$imageResourceId = imagecreatefrompng($file);
$targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
imagepng($targetLayer,$folderPath. $fileNewName. ".". $ext);*/
break;
case IMAGETYPE_JPEG:
$imageResourceId = imagecreatefromjpeg($file);
$targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
imagejpeg($targetLayer,$folderPath. $fileNewName. ".". $ext);*/
echo "works";
break;
default:
echo "Invalid Image type.";
exit;
break;
}
//move_uploaded_file($file, $folderPath. $fileNewName. ".". $ext);
echo "Image Resize Successfully.";
}
function imageResize($imageResourceId,$width,$height) {
$targetWidth =200;
$targetHeight =200;
$targetLayer=imagecreatetruecolor($targetWidth,$targetHeight);
imagecopyresampled($targetLayer,$imageResourceId,0,0,0,0,$targetWidth,$targetHeight, $width,$height);
return $targetLayer;
}
}
voegGebruikerToe($admNaam, $admWw, $admWwConfirm, $conn, "administrator", "ImageUser1");
?>
the example code I found:
<?php
function x ($y) {
function y ($z) {
return ($z*2);
}
return($y+3);
}
$y = 4;
$y = x($y)*y($y);
echo $y;
?>
Fatal error: Uncaught Error: Call to undefined function imageResize() in /var/www/html/v0.2_webpagina_barchart (setupPage)/php/setUpPHP.php:75 Stack trace: #0 /var/www/html/v0.29_webpagina/php/setUpPHP.php(146): voegGebruikerToe('t', 't', 't', Object(mysqli), 'administrator', 'ImageUser1') #1 /var/www/html/v0.2_webpagina /setUp.php(4): include('/var/www/html/v...') #2 {main} thrown in /var/www/html/v0.2_webpagina/php/setUpPHP.php on line 75