Judul : Dynamic Image Gallery using PHP
link : Dynamic Image Gallery using PHP
Dynamic Image Gallery using PHP
Dynamic Image Gallery using PHP:
(1)CREATE TABLE images using following details:
create table images
(
Image_Id int primary key auto_increment,
Image_Title varchar(200),
Image_Name varchar(200)
);
(2)write code for form.html file:
<html>
<body>
<form enctype="multipart/form-data" action="img_db.php" method="POST">
Image Title: <input type="text" name="img_title" /><br /><br />
Image Description: <input type="text" name="img_desc" /><br /><br />
Choose a file to upload: <input name="uploadedfile" type="file" /><br /><br />
<input name="submit" type="submit" value="submit" />
</form>
</body>
</html>
(3)write code for “img_db.php” file:
<?php
if(isset($_POST["submit"]))
{
$img_title=$_POST["img_title"];
$img_desc=$_POST["img_desc"];
}
$img_name=$_FILES["uploadedfile"]["name"];
if (($_FILES["uploadedfile"]["type"]=="image/gif"
|| $_FILES["uploadedfile"]["type"]=="image/jpeg"
|| $_FILES["uploadedfile"]["type"]=="image/pjpeg"
&& $_FILES["uploadedfile"]["size"]<20000))
{
if ($_FILES["uploadedfile"]["error"]>0)
{
echo "Return Code:".$_FILES["uploadedfile"]["error"]."<br />";
}
else
{
$i=1;
$success=false;
$new_img_name=$img_name;
while(!$success)
{
if (file_exists("uploads/".$new_img_name))
{
$i++;
$new_img_name="$i".$img_name;
}
else
{
$success=true;
}
}
move_uploaded_file($_FILES["uploadedfile"]["tmp_name"],"uploads/".$new_img_name);
echo "Stored in: "."uploads/".$new_img_name;
echo "<br />";
$con=mysql_connect("localhost","root","");
mysql_select_db("test",$con);
$qry="INSERT INTO images(Image_Title,Image_Name,img_filename)
VALUES('$img_title','$img_desc','$new_img_name')";
if(!mysql_query($qry))
{
die("An error".mysql_error());
}
else
{
echo "1 row added";
}
}
}
else
{
echo "Invalid file";
}
?>
(4)write code for display.php file which will display your gallery:
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("test",$con);
$qry="SELECT * FROM images";
$result=mysql_query($qry);
//$row=mysql_fetch_array($result);
while($row=mysql_fetch_array($result))
{
echo "
<img
src=uploads/".$row["img_filename"]." height=\"400\"
width=\"400\"/>";
}
?>
output:
Demikianlah Artikel Dynamic Image Gallery using PHP
Sekianlah artikel Dynamic Image Gallery using PHP kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.
Anda sekarang membaca artikel Dynamic Image Gallery using PHP dengan alamat link https://othereffect.blogspot.com/2016/10/dynamic-image-gallery-using-php.html
0 Response to "Dynamic Image Gallery using PHP"
Post a Comment