dalton metzler
dalton metzler

Reputation: 1

HTML, PHP, MYSQL, Upload image and save it's url into database

So i have a mysql database and this is what is contains for each row:

ID | title | subtitle | image | username

Id = Auto

Title is a textbox on site

subtitle is a textbox on site

image you upload it

username is a textbox.

How can i for the image insert the uploaded url where it uploads

being my website.com/uploads

Upvotes: 0

Views: 3871

Answers (2)

dgamma3
dgamma3

Reputation: 2371

you don't save the actual image to the database. rather you save the image name ($_FILES["file"]["name"]) in the database, and the image in a file. then when you want to refer to the image in your website, you refer to the file path of the image i.e.

$image_path = 'images/'
$image_source = $image_path . $_FILES["file"]["name"]

NOTE: $_FILES["file"]["name"] will return something like this: name.extension

Upvotes: 2

Josh
Josh

Reputation: 12566

You can just upload it as usual, via $_FILES, then store the path in the database. Then, set the user's image source equal to that value.

Upvotes: 2

Related Questions