multiple upload put image name in database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fullyloaded
Forum Newbie
Posts: 3
Joined: Sat Nov 05, 2011 5:25 pm

multiple upload put image name in database

Post by fullyloaded »

hi i have this script that works great but now im trying to get it to add the names of the 3 images to my database anyone have any idea how this can be done? i tried everything i know of with no luck thanks...
Code:

Code: Select all

<?php
$connection = mysql_connect("localhost", "????", "????");
mysql_select_db("????", $connection);
$uploaddir = "upload/";
$MaxSize = "600000";
$number_of_files = count($_FILES['userfile']);
for($i=0;$i<=$number_of_files;$i++) {
$filename_format = uniqid(Img_);
if (!$_FILES['userfile']['size'][$i] == 0)
{
if ($_FILES['userfile']['size'][$i] > $MaxSize)
{
echo "ERROR: file too big";
exit;}
$tempfile = $_FILES['userfile']['tmp_name'][$i];
$uploadfile = $_FILES['userfile']['name'][$i];
$extension = $_FILES['userfile']['type'][$i];
if (strstr($extension,"jpeg"))
{
$extension=".jpg";
}
elseif (strstr($extension,"gif"))
{
$extension=".gif";
}
elseif (strstr($extension,"png"))
{
$extension=".png";
}
else
{
echo "ERROR: Only gif/jpeg/png allowed.";
exit;
}
if(copy($tempfile, $uploaddir.$uploadfile))
{
echo "Copy Successfull!";
}
else
{
echo "ERROR: something happened trying to copy the temp file to the folder";
}
if(rename($uploaddir.$uploadfile,$uploaddir.$filename_format.$extension))
{
}else{
$query = "INSERT INTO photos (image1, image2, image3) VALUES ('WHAT TO PUT HERE?','HERE','AND HERE')";  
$result = mysql_query($query);
echo " and renamed to $filename_format$extension";
}
}
else
{
echo "ERROR: Problem renaming the file.. $uploadfile";
}
}
?> 
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: multiple upload put image name in database

Post by Celauran »

fullyloaded wrote:hi i have this script that works great but now im trying to get it to add the names of the 3 images to my database anyone have any idea how this can be done? i tried everything i know of with no luck thanks...
Code:

Code: Select all

$query = "INSERT INTO photos (image1, image2, image3) VALUES ('WHAT TO PUT HERE?','HERE','AND HERE')";  
$result = mysql_query($query);
The path to the file, I'd imagine.
Post Reply