PHP Code:
<?
require_once("conn.php");
require_once("includes.php");
if(isset($_POST['s1']))
{
$MyImages = array(); // Holds the names of the successful uploaded images
$errors = array(); // Holds the errors for all of the images.
foreach($_FILES['images']['tmp_name'] as $i => $tmpImageName) {
// Grabs the original filename
$imageName = $_FILES['images']['name'][$i];
if (file_exists($tmpImageName)) {
$imgSize = getimagesize(trim($tmpImageName));
if ($imgSize === false) {
$errors[$i] = "<b>File #$i ($imageName) is not an image.</b>";
} elseif ($imgSize[0] > 640 || $imgSize[1] > 640) {
$errors[$i] = "<b>Image #$i ($imageName) is to big. It can't be larger then 640 by 640.</b>";
} elseif ($imgSize[2] != 1 && $imgSize[2] != 2) {
$errors[$i] = "<b>Image #$i ($imageName) is of incorrect image type. You can only upload GIF, JPEG files.</b>";
} else {
// Where you want to save the uploaded images.
$uploadDir = 'ds_images/';
// Add the AgentID to the original filename
echo "AgentID: $AgentID<br>";
echo "imageName: $imageName<br>";
$fileName = "$AgentID$imageName";
// Tries to move the uploaded file from the temporary dir to the spesified dir.
// Using the move_upload_file() function instead of copy() because it's made for
// this purpose.
if(move_uploaded_file($fileName, $uploadDir)) {
$MyImages[] = $fileName;
} else {
$errors[$i] = "<b>Image #$i ($imageName) could not be saved.</b>";
}
}
} else {
$errors[$i] = "<b>The temporary file for image #$i ($imageName) could not be located.</b>";
}
}
// Echo out any errormessages. The errors are kept in an array so it's
// possible to echo them out after all the files have been iteratet over.
// That gives you more flexibility where to echo them out.
if(!empty($errors)) {
echo '<strong>The following errror(s) occured:</strong><ul>';
foreach($errors AS $error) {
echo "<li>$error</li>";
}
echo '</ul>';
}
// Check if any images were uploaded
if(!empty($MyImages)) {
$ImageStr = implode('|', $MyImages);
if(!empty($_POST['OldImages'])) {
$ImageStr .= '|' . $_POST['OldImages'];
}
// No images were uploaded
} else {
$ImageStr = $_POST['OldImages'];
}
else
{
$ImageStr = $_POST['OldImages'];
}
$catInfo = explode("|", $_POST[SelectCategory]);
$CategoryID = $catInfo[0];
$SubcategoryID = $catInfo[1];
$SubcategoryName = $catInfo[2];
$q1 = "UPDATE discreet_listings set
CategoryID = '$CategoryID',
SubcategoryID = '$SubcategoryID',
SubcategoryName = '$SubcategoryName',
Weight = '$_POST[Weight]',
city = '$_POST[city]',
state = '$_POST[state]',
oneliner = '$_POST[oneliner]',
greeting = '$_POST[greeting]',
description1 = '$_POST[description1]',
Price = '$_POST[Price]',
incall = '$_POST[incall]',
description2 = '$_POST[description2]',
Height = '$_POST[Height]',
BodyType = '$_POST[BodyType]',
Liner = '$_POST[Liner]',
HairColor = '$_POST[HairColor]',
EyeColor = '$_POST[EyeColor]',
Ethnicity = '$_POST[Ethnicity]',
UserAge = '$_POST[UserAge]',
AttentionColor = '$_POST[AttentionColor]',
DetailsColor = '$_POST[DetailsColor]',
Preference = '$_POST[Preference]',
Site = '$_POST[Site]',
Website = '$_POST[Website]',
Visit = '$_POST[Visit]',
FromMonth = '$_POST[FromMonth]',
FromDay = '$_POST[FromDay]',
ToMonth = '$_POST[ToMonth]',
ToDay = '$_POST[ToDay]',
image = '$ImageStr'
where ListingID = '$_GET[id]' and AgentID = '$_SESSION[AgentID]' ";
mysql_query($q1);
if(mysql_error())
{
echo mysql_error();
}
else
{
header("location:info.php?id=$_GET[id]");
exit();
}
}
}
}
}
Bookmarks