What's new

Pano mag echo ng picture

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,166
Solutions
2
Reaction
103
Points
496
Age
30
pano eecho to para lumabas sa display yun picture anu gagamitin echo sa picture.

ito code ko.

<?php
include "./config/config.php";
$payee_name = $email_address = $username = $password = '';
$payee_nameErr = $email_addressErr =$usernameErr =$passwordErr = '';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(empty($_POST['payee_name'])){
$payee_nameErr = "Payee Name is required!";
}else{
$payee_name = $_POST['payee_name'];
}
if(empty($_POST['email_address'])){
$email_addressErr = "Email Address is required!";
}else {
$email_address = $_POST['email_address'];
}
if(empty($_POST['username'])) {
$usernameErr = " Username os required!";
}else {
$username = $_POST['username'];
}
if(empty($_POST['password'])){
$passwordErr = "Password is required!";
}else {
$password = $_POST['password'];
}
if ($payee_name && $email_address && $username && $password ) {
$check_email = mysqli_query($con, "SELECT * FROM registration WHERE payee_name = '$payee_name'");
$check_email_row = mysqli_num_rows($check_email);
if($check_email_row > 0 ){
$payee_nameErr = "Name is already registered!";
}else {
$target_dir = "./photo_folder/";
$target_file = $target_dir . basename($_FILES["profile-pic"]["name"]);
$uploadOk = 1;
if ($uploadOk == 1) {
if (move_uploaded_file($_FILES["profile-pic"]["tmp_name"], $target_file)) {
$file_path = mysqli_real_escape_string($con, $target_file);

$query = "INSERT INTO registration (payee_name, email_address, username, password, user_type, img) VALUES ('$payee_name', '$email_address', '$username', '$password', '2', '$file_path')";
$result = mysqli_query($con, $query);

echo "<div class='alert alert-success' role='alert'>
A simple success alert—check it out!
</div>";

}

}
}}}

?>
<!DOCTYPE html>
<HTMl:5>
<head>
<title>signup</title>
<link rel="stylesheet" href="../Innerjoin/css/bootstrap.css">
<link rel="stylesheet" href="../Innerjoin/css/style.css">
<script src="../Innerjoin/js/bootstrap.bundle.js"></script>
<script src="You do not have permission to view the full content of this post. Log in or register now." integrity="sha256-JlqSTELeR4TLqP0OG9dxM7yDPqX1ox/HfgiSLBj8+kM=" crossorigin="anonymous"></script>
</head>
<body>
<?php




?>

<form method="POST" action="<?php htmlspecialchars($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data">
<!-- <div
<div class="modal-dialog" role="document">
<div class="modal-content rounded-4 shadow">
<div class="modal-header p-5 pb-4 border-bottom-0">
<h1 class="fw-bold mb-0 fs-2">Sign up for free</h1> -->
<div class="body-background">
<div class="container col-xl-6 col-xxl-8 px-4 py-5 ">
<div class="modal-content rounded-4 shadow align-items-center bg-body-tertiary">
<div class="modal-header p-4 pb-2 border-bottom-0">
<h1 class="fw-bold mb-0 fs-2 ">BSWM REGISTRATION</h1>
</div>

<form class="">
<div class="container col-xl-10 ">
<div class="form-group mt-1 ">
<label for="exampleInputEmail1">Payee Name:</label>
<input type="text" class="form-control form-control-sm rounded-3" name="payee_name" value="" id="floatingInput" placeholder="Payee Name" required>
<small id="emailHelp" class="form-text text-muted">Registered your name base on your account</small>
</div>
<div class="form-group mt-2">
<label for="exampleInputEmail1">Email Address:</label>
<input type="text" class="form-control form-control-sm rounded-3" name="email_address" value="" id="floatingPassword" placeholder="Email Address" required >
</div>
<div class=" form-group mt-2">
<label for="exampleInputEmail1">Nickname:</label>
<input type="text" class="form-control form-control-sm rounded-3" name="username" value="" id="floatingInput" placeholder="Nickname" required >
</div>
<div class=" form-group mt-2">
<label for="exampleInputEmail1">Password:</label>
<input type="password" class="form-control form-control-sm rounded-3" name="password" value="" id="floatingPassword" placeholder="Password" required>
</div>
<div class="mt-3">
<label for="formFile" class="form-label ">Upload Image</label>
<input class="form-control" type="file" name="profile-pic" onchange ="displayPreview(this.files)" id="formFile">
</div>
<center>
<span id="preview"></span>
</center>
<div class="checkbox mt-3 text-body-secondary">
<label>
<small><input class="" type="checkbox" value="remember-me"> By clicking Sign up, you agree to the terms of use.</small>
</label>
</div>
<hr class="my-4">
<button class="w-100 mb-2 btn btn-sm btn-lg rounded-3 btn-primary" name="update" type="submit">Sign up</button>
<div class=" mb-3 text-center fs-6 fw-bold">
<label>
<small class="text-body-secondary"> Already have an Account <a href ="login.php">Login</a>.
</label>
</div>
</div>
</form>
</div>
</div>
</div>
</form>
<?php
$target_dir = "./photo_folder/";
$uploadErr = "";
if (isset($_POST["update"])){
$target_file = $target_dir . "/" . basename($_FILES["profile-pic"]["name"]);
$uploadOk = 1;
if(file_exists($target_dir)) {
$target_file = $target_dir . rand(1,9) . rand(1,9) . rand(1,9) . rand(1,9) . "_" .basename($_FILES["profile-pic"]["name"]);
$uploadOk = 1;
}
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if($_FILES["profile-pic"]["size"] > 5000000000000000000 ) {
$uploadErr = "Sorry, your file is too large";
$uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
$uploadErr = "Sorry, only JPG, PNG, JPEG and GIF files are allowed";
$uploadOk = 0;
}
else {
echo "sorry , there was an error uploading file.";
}}
?>
<script type = "application/javascript">
var _URL = window.URL || window.webkitURL;
function displayPreview(files){
var file = files[0];
var img = new Image();
var sizeKB = file.size / 1024;
img.onload =function(){
$(img).addClass('resized-image');
$('#preview').append(img);
}
img.src = _URL.createObjectURL(file);
}
</script>
</body>
</HTMl:5>
 
To display the uploaded picture on the webpage using the echo function, you can add the following code:

PHP:
// After the successful upload of the image
if (move_uploaded_file($_FILES["profile-pic"]["tmp_name"], $target_file)) {
    $file_path = mysqli_real_escape_string($con, $target_file);

    $query = "INSERT INTO registration (payee_name, email_address, username, password, user_type, img) VALUES ('$payee_name', '$email_address', '$username', '$password', '2', '$file_path')";
    $result = mysqli_query($con, $query);

    // Display the uploaded image
    echo "<div class='alert alert-success' role='alert'>
        A simple success alert—check it out!
    </div>";
    echo "<img src='$file_path' alt='Uploaded Image' width='200'>"; // Add this line
}

This will display a success message and the uploaded image below it. The img tag is used to display the image, and the src attribute is set to the file path of the uploaded image. Adjust the width attribute as needed to fit the image size on your webpage.

Make sure to add the code at the appropriate location in your existing code.
 

Similar threads

Back
Top