Advertisement
mauricemuteti

Upload And Insert Image Into Mysql Database Using Php Html

Apr 4th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. <?php
  2. //This code shows how to Upload And Insert Image Into Mysql Database Using Php Html.
  3. //connecting to uploadFile database.
  4. $conn = mysqli_connect("localhost", "root", "", "uploadFile");
  5. if($conn) {
  6. //if connection has been established display connected.
  7. echo "connected";
  8. }
  9. //if button with the name uploadfilesub has been clicked
  10. if(isset($_POST['uploadfilesub'])) {
  11. //declaring variables
  12. $filename = $_FILES['uploadfile']['name'];
  13. $filetmpname = $_FILES['uploadfile']['tmp_name'];
  14. //folder where images will be uploaded
  15. $folder = 'imagesuploadedf/';
  16. //function for saving the uploaded images in a specific folder
  17. move_uploaded_file($filetmpname, $folder.$filename);
  18. //inserting image details (ie image name) in the database
  19. $sql = "INSERT INTO `uploadedimage` (`imagename`)  VALUES ('$filename')";
  20. $qry = mysqli_query($conn,  $sql);
  21. if( $qry) {
  22. echo "image uploaded";
  23. }
  24. }
  25.  
  26. ?>
  27.  
  28.  
  29. <!DOCTYPE html>
  30. <html>
  31. <body>
  32. <!--Make sure to put "enctype="multipart/form-data" inside form tag when uploading files -->
  33. <form action="" method="post" enctype="multipart/form-data" >
  34. <!--input tag for file types should have a "type" attribute with value "file"-->
  35. <input type="file" name="uploadfile" />
  36. <input type="submit" name="uploadfilesub" value="upload" />
  37. </form>
  38. </body>
  39. </html>
  40.  
  41. For video tutorial visit https://www.youtube.com/watch?v=wvoUS_PUXMg
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement