Reputation: 651
I have two tables:
first and parent "register"
and second is
What I wanted is to create a script in which one User with unique SN
whenever upload a pic that pic path save in "userimg" i user SN as foreign key in userimg
code is below
if(isset($_POST['SN']))
{
$filename = $_FILES['upload_image']['name'].$user_SN;
$filesize = $_FILES['upload_image']['size'];
$filetype = $_FILES['upload_image']['type'];
$target_path ="uploads/". basename( $filename );
if (move_uploaded_file($_FILES['upload_image']['tmp_name'], $target_path))
{
$result = $target_path ;
$sql="INSERT INTO userimg (src, size, type,SN ) VALUES ('".$result."', '".$filesize."','".$filetype."','".$user_SN."')";
echo $sql." ";
echo $filesize." ";
echo $filetype." ";
$inst=mysql_query($sql);
if (!$inst)
{
print "error";
}
}
}
This script is working for one picture but what I want is like multiple uploads (just like a gallery) by user and saving that path in my second table.
Do I need to create a userimg table for each SN means user? What am I missing?
[EDIT]
Problem solved. Mistake was Making SN in userimg a unique and i rename image like this(code is below ) - Thankx Tuhin!
if(isset($_POST['SN']))
{
$filename = $_FILES['upload_image']['name'];
$filesize = $_FILES['upload_image']['size'];
$filetype = $_FILES['upload_image']['type'];
$timeSt = time();
$info = pathinfo($filename);
$name = $info['filename'];
$format = $info['extension'];
$target_path ="uploads/".basename( $name )."_".$user_SN."_".$timeSt.".".$format;
}
Upvotes: 0
Views: 235
Reputation: 980
If the same user (means same SN value) tries to upload the same image (means already uploaded by him with same image name in this app) then the 'src' column in the second table will be same. Also if the uploaded folder first image file will be replaced by the newer file. Thats why I proposed you to add time stamp and rename the uploaded image file and store it into the DB.
Upvotes: 1