Hello,
I´m working on improving my site alot right now but I have gotten stuck in a thing I would like to improve so I hope someone can help me.
I would like to save the picturenames in the database and also which folder they are stored in. But I also have some question how to do this since it is the first time I try this.
- How should the database be, which tabels and stuff like that would I need?
This is what I think I need correct me if I´m wrong.
I think every picture should have a image_id that is unique and there should also be a gallery_id that is the same for all the pictures in the same gallery. I use a script so I can upload up to a 100 images at the same time. Then I would like the images to have an game_id and ofcourse the picture name. I´m also going to save a date in the database. All the extra is just for my site but the things I would like to know if it is right to have a unique image_id and then a gallery_id that is for the pictures in the same gallery.
How do I setup my code so it saves a diffrent unique image_id for all the images? Since I upload alot of at the same time, I think I need to use auto_increment, but how does it work when I upload alot of pictures at the same time.
The next problem is how do I make the code do so it saves all the images that are uploaded at the same time gets the same gallery_id? And so I dont have to write a gallery_id every time and that also in someway uses a sort of auto_increment?
I think this is the last problem. I have the code that uploads all the pictures and writes out all the names but have do I make it write all the info to my database?
I hope someone can help me and maybe point me in the right direction since I have been trying for two days without succes.
Here is my upload code:
$success = 0;
$fail = 0;
$uploaddir = "../../Bilder/Bildserier/$mapp/";
for ($i=0;$i<100;$i++)
{
if($_FILES['userfile']['name'][$i])
{
$imagename = basename($_FILES['userfile']['name'][$i]);
$uploadfile = $uploaddir . basename($_FILES['userfile']['name'][$i]);
$ext = strtolower(substr($uploadfile,strlen($uploadfile)-3,3));
if (preg_match("/(jpg|gif|png|bmp)/",$ext))
{
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $uploadfile))
{
$success++;
}
else
{
echo "Error Uploading the file. Retry after sometime.\n";
$fail++;
}
}
else
{
$fail++;
}
}
}
echo "<br /> Number of files Uploaded:".$success;
echo "<br /> Number of files Failed:".$fail;
echo "<br /><br /><a href='nyheter.php'>Back to the form! </a><br />";
var_dump($imagename); //I wrote this to check so that I actully got all the image names.