tring to create a website where user can upload image.
i have 2 database
1-user(database)
1- which has user_id, email, passwod
2-image(database)
2-which has image_id, user_id, image(store image here), image_name ...etc
on upload.php page user has to fill this form hit sumbit. and it will run php code on upload.php
<form action="upload.php" method='post' enctype = 'multipart/form-data'>
ImageName: <input class = "text" type="text" name="imagename" /><br/>
Description: <input class = "text" type="text" name="description" /><br/>
feedback<textarea cols="16" rows="4" nicewebsite> </textarea><br/>
<input type ="file" name="fileupload" /><br/>
<input type="submit" name="submit" value="sumbit" /><br/>
<a href="index.php">[BACK]</a>
</form>
here i want to insert image to database. so for ex. if a user hwoarang(user_id 30) upload a image.
i want to store that image into table called image image_id(1), user_id(30), image(store image here)..etc
//store image in $image
$image = file_get_contents($_FILES['fileupload']['tmp_name']);
//store image name in $image_full_name(.jpeg)
$image_full_name = $_FILES['fileupload']['name'];
//store image size in $image_size
$image_size = getimagesize($_FILES['fileupload']['tmp_name']);
//test if its a image or file
if($image_size == FALSE)
{
echo "Thats not a image";
}
else
{
//insert information into database
if(!$insert = mysql_query("INSERT INTO VALUES(NULL, '', '$image', '$image_full_name', '', '', '', '')"))
{
echo "problem uploading image";
}
else
{
$lastid = mysql_insert_id();
echo "Image upoaded.<p />your image:<p /><img src=get.php?image_id=$lastid>";
}
full code=====================================================================================================
upload.php
<?php
session_start();
include("connect.php");
$user = $_SESSION['username'];
$file = $_FILES['fileupload']['tmp_name'];
$upload_error = "";
//user log in
if($user)
{
if($file)
{
//user get submit button
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
//check for error first
//scussess
//store image in $image
$image = file_get_contents($_FILES['fileupload']['tmp_name']);
//store image name in $image_full_name(.jpeg)
$image_full_name = $_FILES['fileupload']['name'];
//store image size in $image_size
$image_size = getimagesize($_FILES['fileupload']['tmp_name']);
//test if its a image or file
if($image_size == FALSE)
{
echo "Thats not a image";
}
else
{
//insert information into database
if(!$insert = mysql_query("INSERT INTO VALUES(NULL, '', '$image', '$image_full_name', '', '', '', '')"))
{
echo "problem uploading image";
}
else
{
$lastid = mysql_insert_id();
echo "Image upoaded.<p />your image:<p /><img src=get.php?image_id=$lastid>";
}
}
}
}
else
{
echo "Please select an image.";
}
}
else
{
die("plz log in!");
}
?>
<!-- enctype for upload images-->
<form action="upload.php" method='post' enctype = 'multipart/form-data'>
ImageName: <input class = "text" type="text" name="imagename" /><br/>
Description: <input class = "text" type="text" name="description" /><br/>
feedback<textarea cols="16" rows="4" nicewebsite> </textarea><br/>
<input type ="file" name="fileupload" /><br/>
<input type="submit" name="submit" value="sumbit" /><br/>
<a href="index.php">[BACK]</a>
</form>
get.php=====================================================================================================
<?php
include("connect.php");
$user_id = $_REQUEST['user_id'];
$image = mysql_query("SELECT * FROM image WHERE user_id = $user_id");
$image = mysql_fetch_assoc($image); //get access to image table
$image = $image['image'];
header("Content-type: image/jpeg");
?>