I know this question has been asked many times before, but i still can't understand it even if i do many times. I need someone to explain things to me but i have no help here. I hope you guys can help me with my coding.
I try to do an upload page, it's working just fine but i just don't understand how people can grab the image location directory/url and save it into a database. I can show the image but the image is being shown from the folder. I mean i think the directory of the image after it being uploaded into a uploads/
folder isn't being save into the database.
I have a database name images
and the table images
. And the columns are id
, name
, and ext
.
Here is my coding for index.php
:
<html>
<head>
</head>
<body>
<!--Upload form-->
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="file"/><br/>
<input type="submit" name="submit" value="Upload">
</form>
<?php
//include the connect.php file
include ('connect.php');
if (isset($_POST['submit']))
{
//location, where the image will be saved
$loc= "uploads/";
if ($_FILES["file"]["type"] == "image/png"
|| $_FILES["file"]["type"] == "image/jpeg"
|| $_FILES["file"]["type"] == "image/jpg"
|| $_FILES["file"]["type"] == "image/gif")
{
//script
$file=explode(".", $_FILES["file"]["name"]);
mysql_query("INSERT INTO images VALUES ('','".$file[0]."', '".$file[1]."')");
$id = mysql_insert_id();
$newname = "$id.$file[1]";
$path = "$loc$newname.ShowUploadKatSini.php";
move_uploaded_file($_FILES["file"]["tmp_name"], $path);
echo"Your image has been uploaded successfully. Visit this link to see ur image <a href='$path'>Click HERE</a>.";
}
else
{
echo"Invalid file!";
}
}
?>
</body>
</html>
And here is for connect.php
:
$connect = mysql_connect("localhost","root");
//select database
mysql_select_db("images",$connect);
?>
My real question is how to grab the picture's directory/url into a database and make the pictures that i upload shown in certain page, let say the page name dress.html