it was working fine on live host earlier but now i updated my php version to 8.1 and stopped working . But when i check it on xampp local server it is working fine .
my HTML code is :-
<form method="POST" id="name-form" enctype="multipart/form-data">
<div class="h4">Update Display</div>
<input type='file' name="dp" class="input-form" accept="image/*">
<input type="submit" value="Update" name="dp" class="edit-button">
</form>
and php is :-
function compressImage($source, $destination, $quality){
$imgInfo = getimagesize($source);
$dataMine = $imgInfo['mime'];
switch ($dataMine) {
case 'image/jpeg':
$image = imagecreatefromjpeg($source);
break;
case 'image/png':
$image = imagecreatefrompng($source);
break;
case 'image/jpg':
$image = imagecreatefromjpeg($source);
break;
default:
$image = imagecreatefromjpeg($source);
}
imagejpeg($image, $destination, $quality);
// final Return compressed image
return $destination;
}
if (isset($_POST['dp'])) {
$filename = $_FILES["dp"]["name"];
$tempname = $_FILES["dp"]["tmp_name"];
$imgsize = $_FILES["dp"]["size"];
$folder = "covers/" . time() . $filename;
$fold = "covers/" . time() . $filename;
$allowed = array('jpeg', 'png', 'jpg');
$ext = pathinfo($folder, PATHINFO_EXTENSION);
if (!in_array($ext, $allowed)) {
$errors['DP'] = "Sorry, only JPG, JPEG, PNG files are allowed.";
}
if ($imgsize > 3098152) {
$errors['size'] = "File size must be less than 3MB";
}
if (count($errors) === 0) {
$compressedImage = compressImage($tempname, $folder, 40);
if ($compressedImage) {
move_uploaded_file($compressedImage, $folder);
$pd = ("update inst set cover = :folder where uid = :uid limit 1 ");
$result_to_update_dp = $conn->prepare($pd);
$result_to_update_dp->bindParam(':folder', $fold, PDO::PARAM_STR);
$result_to_update_dp->bindParam(':uid', $uid, PDO::PARAM_STR);
$dp_update = $result_to_update_dp->execute();
if ($dp_update) {
$_SESSION['success'] = "Profile Picture Updated Successfully. May Reflect After Some Time";
$uploadDir = "covers/";
//$_SERVER['DOCUMENT_ROOT'].
$uploadFile = $uploadDir . basename(time() . $filename);
$uploadRequest = array(
'fileName' => basename($uploadFile),
'fileData' => base64_encode(file_get_contents($uploadFile))
);
header("location:index.php");
exit();
}
}
} else {
$errors['upload'] = "OOps Something Wrong ! Try Again";
}
}
it is keep saying Warning: Undefined Array Key "Dp" In /Home/Myclass2/Public_html/User.Php On Line 403
Warning: Trying To Access Array Offset On Value Of Type Null In /Home/Myclass2/Public_html/User.Php On Line 403
Warning: Undefined Array Key "Dp" In /Home/Public_html/User.Php On Line 404
Warning: Trying To Access Array Offset On Value Of Type Null In /Home/Myclass2/Public_html/User.Php On Line 404
Warning: Undefined Array Key "Dp" In /Home/Public_html/User.Php On Line 405
Warning: Trying To Access Array Offset On Value Of Type Null In /Home//Public_html/User.Php On Line 405
But it is working fine localhost .
thanks in advance !