Avatar of sanchit gupta
sanchit gupta

asked on 

Inserting images in database PDO

I have created a very basic form for inserting data in database PDO. I'm done with the url, name and title but got stucked with the image. How to get image inserted into database through the "folder". I also want to fetch all the details onto some another page.
Any help in styling up these would also be highly appreciated.
include ("./inc/header.inc.php");
if(isset($_POST['newpost'])) {
    $userid = Login::isLoggedin();
    $filename = $_FILES['fileToUpload']['name'];
    $filetemp = $_FILES['fileToUpload']['tmp_name'];
    $filesize = $_FILES['fileToUpload']['size'];
    $filebasename = basename($_FILES['fileToUpload']['name']);
    DB::query('INSERT INTO links VALUES (\'\', :urlInput, :fileToUpload, :title, NOW(), :userid, 0)', array(':urlInput'=>$urlInput, ':fileToUpload'=>$fileToUpload, ':title'=>$title, ':userid'=>$userid));


<form action="submit.php" method="post">
<input type="url" name="urlInput" value="" placeholder="" required><p />
<input type="file" name="fileToUpload" value="" placeholder="" accept="image/*" required><p />
<input type="text" name="title" value="" placeholder="" required><p />
<input type = "submit" name="newpost" value="Submit"/>

Open in new window


Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon