Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Inserting images in database PDO

Avatar of sanchit gupta
sanchit gupta asked on
PHP
16 Comments1 Solution1303 ViewsLast Modified:
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.
<?php
ob_start();
include ("./inc/header.inc.php");
$fileToUpload="";
if(isset($_POST['newpost'])) {
    $urlInput=$_POST['urlInput'];
    $fileToUpload=$_FILES['fileToUpload']['name'];
    $title=$_POST['title'];
    $userid = Login::isLoggedin();
    $filename = $_FILES['fileToUpload']['name'];
    $filetemp = $_FILES['fileToUpload']['tmp_name'];
    $filesize = $_FILES['fileToUpload']['size'];
    $filebasename = basename($_FILES['fileToUpload']['name']);
    $dir="userdata/folder/";
    $finaldir=$dir.$filebasename;
    move_uploaded_file($filetemp,$finaldir);
    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">
        <p><label><b>URL</b></label><br>
<input type="url" name="urlInput" value="" placeholder="" required><p />
        <p><label><b>Image</b></label><br>
<input type="file" name="fileToUpload" value="" placeholder="" accept="image/*" required><p />
        <p><label><b>Title</b></label><br>
<input type="text" name="title" value="" placeholder="" required><p />
<input type = "submit" name="newpost" value="Submit"/>
</form>
ASKER CERTIFIED SOLUTION
Avatar of Imran Ali
Imran AliFlag of Pakistan imageWeb Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 16 Comments.
See Answers