Answers for "php image upload and display from database"

PHP
2

php image upload write to server

<?php error_reporting(0);

$msg = "";

if ( isset( $_POST['upload']) ) {

	$filename = $_FILES["uploadfile"]["name"];
	$tempname = $_FILES["uploadfile"]["tmp_name"];
    $folder   = $filename;

    if ( move_uploaded_file( $tempname, $folder ) ) {
        $msg = "Image uploaded successfully";
    } else{
        $msg = "Failed to upload image";
	}
}
?>

<!DOCTYPE html>
<html>
    <head>
    <title>Image Upload</title>
    </head>
    <body>

    <h2><?php echo $msg; ?></h2>
    <form method="POST" action="" enctype="multipart/form-data">
        <input type="file" name="uploadfile"/>
        <button type="submit" name="upload">UPLOAD</button>
    </form>
    </body>
</html>
Posted by: Guest on June-17-2021
2

img upload in php

if(isset($_FILES['image']))
                {
                    $img_name = $_FILES['image']['name'];      //getting user uploaded name
                    $img_type = $_FILES['image']['type'];       //getting user uploaded img type
                    $tmp_name = $_FILES['image']['tmp_name'];   //this temporary name is used to save/move file in our folder.
                    
                    // let's explode image and get the last name(extension) like jpg, png
                    $img_explode = explode(".",$img_name);
                    $img_ext = end($img_explode);   //here we get the extension of an user uploaded img file

                    $extension= ['png','jpeg','jpg','gif']; //these are some valid img extension and we are store them in array.
Posted by: Guest on August-25-2021
0

how to store and retrieve image from database in php

// Get the name of images
  	$Get_image_name = $_FILES['image']['name'];
  	
  	// image Path
  	$image_Path = "images/".basename($Get_image_name);

  	$sql = "INSERT INTO student_table (imagename, contact) VALUES ('$Get_image_name', 'USA')";
  	
	// Run SQL query
  	mysqli_query($conn, $sql);

  	if (move_uploaded_file($_FILES['image']['tmp_name'], $image_Path)) {
  		echo "Your Image uploaded successfully";
  	}else{
  		echo  "Not Insert Image";
  	}
  }
Posted by: Guest on July-07-2020

Code answers related to "php image upload and display from database"

Browse Popular Code Answers by Language