<?php if(!$conn){ } ?>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/> </head> <body> <nav class="navbar navbar-default"> <div class="container-fluid"> <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a> </div> </nav> <div class="col-md-3"></div> <div class="col-md-6 well"> <h3 class="text-primary">PHP - Simple Upload Only Image</h3> <hr style="border-top:1px dotted #ccc;"/> <form method="POST" enctype="multipart/form-data"> <div class="form-inline"> <input type="file" name="file" class="form-control"/> <br /> <br /> <center><button class="btn btn-primary btn-sm" name="upload"><span class="glyphicon glyphicon-upload"></span> Upload</button></center> </div> </form> <br /> <?php include 'upload.php'?> </div> </body> </html>
<?php require_once 'conn.php'; $file_name = $_FILES['file']['name']; $file_temp = $_FILES['file']['tmp_name']; $path = "upload/".$file_name; mysqli_query($conn, "INSERT INTO `upload` VALUES('', '$file_name', '$date_upload')") or die(mysqli_error()); echo "<center><img src='upload/".$file_name."' width='400px' height='400px'/></center>"; } }else{ echo "<center><h3 class='text-danger'>Only image format can be upload</h3></center>"; } } ?>