Maaung ud2.. patudlo tana ko unsaon di magdisplay ug image ug store ang image sa php/mysql. kanang magbrowse ka daan sa image na imu gus2 e store tapos display daun.. naa man tutorial ako gsunod sa phpacademy sa youtube.. pero ang gina hatag na image kay broken..
<!--index.php na page-->
<?php include_once 'mydb_connect.php';?><html>
<head>
<title>image upload</title>
</head>
<body>
<form action = "index.php" method = "POST" enctype = "multipart/form-data">
<label>File: <input type = "file" name = "image"/>
<input type = "submit" value = "Upload"/></label>
</form>
<?php
$file = @$_FILES['image']['tmp_name'];
if(!isset($file)) {
echo "Please select image";
}
else {
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['image']['name']);
$image_size = getimagesize($_FILES['image']['tmp_name']);
if($image_size == FALSE) {
echo "Thats not an image!";
}
else {
if(!$insert = mysql_query("INSERT INTO imageupload VALUES('','$image_name','$image')")) {
echo "Problem Uploading Image";
}
else {
$img_id = mysql_insert_id();
echo "Image uploaded.<p/> Your image: <p /><img src=get_img.php?id=$img_id";
}
}
}
?>
</body>
</html>
<!--get_img.php na page-->
<?php include_once 'mydb_connect.php';?>
<?php
$id = addslashes($_REQUEST['id']);
$image = mysql_query("SELECT * FROM imageupload WHERE img_id = $id");
$image = mysql_fetch_assoc($image);
$image = $image['image'];
header("Content-type: image/jpeg");
echo $image;
?>
-mao ni ang code..
Salamat!