I'm trying to take the array of images from form and check them for file types and size. As of now it's not working and if I input a file over 10kb it still posts without displaying the $message variable. I think I may have to break apart the array before I start checking for size, etc. but I'm not really sure.
Thanks
if(isset($_POST[s1]))
{
//manage files
if(empty($_FILES[images]))
{
$max_size = 10000;
$is_uploaded_file = true;
$size = true;
$type = true;
if (!is_uploaded_file($_FILES[images][name]
)) {$is_uploaded_file = FALSE;}
if ($_FILES[images][size] > $max_size)
{
$size = FALSE;
$message[] = 'The file is too big. You must keep image size under 10kb.';
}
if (($_FILES[images][type] != 'image/pjpeg') && ($_FILES[images][type] != 'image/jpeg'))
{
$type = FALSE;
$message[] = 'Sorry, only .jpg formats allowed. ';
}
if (!$is_uploaded_file || !$size || !$type)
{
$message[] = 'Upload has failed.';
}
}
if(!empty($_FILES[images]))
{
while(list($key,$value) = each($_FILES[images][name]))
{
if(!empty($value))
{
$NewImageName = $t."_".$value;
copy($_FILES[images][tmp_name][$key], "images/blingpics/".$NewImageName);
$MyImages[] = $NewImageName;
}
}
if(!empty($MyImages))
{
$ImageStr = implode("|", $MyImages);
}
$q1 = "insert into class_catalog set
MemberID = '$_SESSION[MemberID]',
ProductType = '$_POST[ProductType]',
url = '$_POST[url]',
CategoryID = '$_POST[CategoryID]',
ProductName = '$_POST[ProductName]',
Description = '$_POST[Description]',
images = '$ImageStr',
Price = '$_POST[Price]',
DatePosted = '$t',
DateExp = '$_SESSION[AccountExpDate]',
FeaturedStatus = '$_POST[sp]' ";
//echo $q1;
mysql_query($q1) or die(mysql_error());
//get the posted offers
$q1 = "select count(*) from class_catalog where MemberID = '$_SESSION[MemberID]' ";
$r1 = mysql_query($q1) or die(mysql_error());
$a1 = mysql_fetch_array($r1);
if($_SESSION[MaxOffers] == '0' || $_SESSION[AccountStatus] == 'inactive' || $a1[0] >= $_SESSION[MaxOffers])
{
header("location:more.php?st=1");
exit();
}
}
header("location:AddAsset.php");
exit();
//______________Display Form Below
} else { ?>
<form method=post action="<?php echo $_SERVER['PHP_SELF']?>" name="PostForm" onsubmit="return CheckOffer();" enctype="multipart/form-data">
//form here
<? //print error messages here
if ($message) {
echo "<div align=\"left\"><font color=red></b><br />\n";
foreach ($message as $key => $value) {
echo "$value";
}
echo "<br></font><br>";
} ?>
<input type=file name="images[]" size=31>
<br> <input type=file name="images[]" size=31>
<br> <input type=file name="images[]" size=31>
<input type=submit name=s1 value="Submit">
</form>
<? } ?>