upload image in php with url code example
Example 1: how to upload image in php and store in database and folder
$Get_image_name = $_FILES['image']['name'];
$image_Path = "images/".basename($Get_image_name);
$sql = "INSERT INTO student_table (imagename, contact) VALUES ('$Get_image_name', 'USA')";
mysqli_query($conn, $sql);
if (move_uploaded_file($_FILES['image']['tmp_name'], $image_Path)) {
echo "Your Image uploaded successfully";
}else{
echo "Not Insert Image";
}
}
Example 2: php upload from url
<?php
if(isset($_POST['get_image']))
{
$url=$_POST['img_url'];
$data = file_get_contents($url);
$new = 'images/new_image.jpg';
file_put_contents($new, $data);
echo "<img src='images/new_image.jpg'>";
}
?>