Page 1 of 1

multiple upload put image name in database

Posted: Fri Apr 06, 2012 1:22 am
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";
}
}
?> 

Re: multiple upload put image name in database

Posted: Fri Apr 06, 2012 6:45 am
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.