Here is a script that I wrote that handles multiple uploads. I am using it to handle 2 uploads. It first uploads to the temp directory then moves the upload to the images directory which I changed the permissions on to 777. It then stores the name fo the image such as me.jpg in a database.
foreach($_FILES as $varname => $value)
$_FILES[$varname];
// Check to see if the file has been uploaded and upload it to the
// images directory
if ($_FILES['picture1']['name'] != "")
{
move_uploaded_file($_FILES['picture1']['tmp_name'], $path . $_FILES['picture1']['name']) or die("could not move the file picture 1");
echo "Picture 1 was uploaded successfully.";
}
if ($_FILES['picture2']['name'] != "")
{
move_uploaded_file($_FILES['picture2']['tmp_name'], $path . $_FILES['picture2']['name']) or die("could not move the file picture 2");
echo "Picture 2 was uploaded successfully.";
}
if (($_FILES['picture1']['name'] != "") || ($_FILES['picture2']['name'] != ""))
{
$result = @ mysql_query ("SELECT picid FROM picture WHERE picid = $picid", $connection);
$rows = @ mysql_num_rows($result);
if ($rows == 0)
{
if (($_FILES['picture1']['name'] != "") && ($_FILES['picture2']['name'] != ""))
{
if (@ mysql_query ("INSERT INTO picture SET picid = $picid, pageid = $pageid, " .
"picture1 = \"" . $_FILES['picture1']['name'] . "\", " .
"picture2 = \"" . $_FILES['picture2']['name'] . "\"", $connection))
echo "MySQL insert query for picture 1 and picture 2 successful.";
}
else
die("You are inserting pictures for the first time. Go back to the form and insert picture 1 and picture 2.");
}
else
{
if ($_FILES['picture1']['name'] != "")
{
if (@ mysql_query ("UPDATE picture SET " .
"picture1 = \"" . $_FILES['picture1']['name'] . "\", " .
"WHERE picid = $picid", $connection))
echo "MySQL update of picture 1 successful.";
}
if ($_FILES['picture2']['name'] != "")
{
if (@ mysql_query ("UPDATE picture SET " .
"picture2 = \"" . $_FILES['picture2']['name'] . "\", " .
"WHERE picid = $picid", $connection))
echo "MySQL update of picture 2 successful.";
}
}
}