Forum Moderators: coopster
if((isset($_GET['snd'])) && (isset($_POST['img_upl_send']))) {
$amt2upl = $_GET['amt'];
$xu = 1;
$imgerrors=0;
$mainimgnum = $_POST['main_img'];
$sn_imgup = $_SESSION['stagename'];
define('GW_UPLOADPATH', '../'.$sn_imgup.'/images/');
define('GW_MAXFILESIZE', 432768);
$uploadArray= array();
while($xu <= $amt2upl) {
$uploadArray[] = $_POST['image'.$xu];
$xu++;
}
foreach($uploadArray as $file) {
$memimgname = $_FILES["$file"]['name'];
$extension = substr(strrchr($memimgname, "."), 1);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) {
echo "<div class=\"titlebar\">Unknown File Extension!";
echo $extension;
echo "<br> <a href='javascript:history.back(1);'><< Back</a></div>";
echo "</div></div><div id=\"footer\">";
include("includes/footer.php");
exit;
$imgerrors=1;
} else {
$memimgsize=filesize($_FILES["$file"]['tmp_name']);
if ($memimgsize > GW_MAXFILESIZE){
echo "<div class=\"titlebar\">You have exceeded the size limit!";
echo "<br> <a href='javascript:history.back(1);'><< Back</a></div>";
echo "</div></div><div id=\"footer\">";
include("includes/footer.php");
exit;
$imgerrors=1;
} else {
$cld = generateCode($length=3);
$image_name=$cld.'image.'.$extension;
$newname=GW_UPLOADPATH.$image_name;
$copied = move_uploaded_file($_FILES["$file"]['tmp_name'], $newname);
if (!$copied) {
echo "<div class=\"titlebar\">Image Upload Error!";
echo "<br> <a href='javascript:history.back(1);'><< Back</a></div>";
echo "</div></div><div id=\"footer\">";
include("includes/footer.php");
exit;
$imgerrors=1;
} else {
echo "Image OK"; //will be inserting into database here
}
}
}
}
}
if((isset($_GET['sel'])) && (isset($_POST['img_cnt']))) {
$all_amt = $_POST['amt_des'];
$xu = 1;
echo "<div class=\"titlebar\"><h2>Images to upload:</h2>";
echo "<form action=\"ood_images.php?n=y&snd=y&amt=".$all_amt."\" method=\"post\" name=\"imgs_upl\"><br />";
echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr class=\"top\"><td>Picture #</td><td>Select Image</td><td>Main Image?</td></tr>";
echo "<tr><td> </td><td> </td><td> </td></tr>";
while($xu <= $all_amt) {
echo "<tr><td>Picture ".$xu.":</td><td><input type=\"file\" name=\"image".$xu."\" /></td><td><input type=\"radio\" name=\"main_img\" value=\"".$xu."\"/></td></tr>";
$xu++;
}
echo "<tr><td> </td><td>Main Picture Already Uploaded:</td><td><input type=\"radio\" name=\"main_img\" value=\"none\"/></td></tr>";
echo "<tr><td> </td><td> </td><td><input type=\"submit\" name=\"img_upl_send\" value=\"Upload Pictures\" /></td></tr>";
echo "</table></form></div>";
}
$extension = strtolower(substr($memimgname, strrchr($memimgname, ".") + 1));
echo "<form enctype=\"multipart/form-data\" action=\"ood_images.php?n=y&snd=y&amt=".$all_amt."\" method=\"post\" name=\"imgs_upl\"><br />";
echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"432768\">\n";
$uploadArray = array();
while($xu <= $amt2upl) {
$imgnum = "image".$xu;
$uploadArray[] = $_POST[$imgnum];
$xu++;
}
echo "<div class=\"titlebar\">Errors and output:<br />";
print_r($_POST);
echo "<br />";
print_r($uploadArray);
echo "<br />";
if(is_uploaded_file($_POST['image1'])) { // just choose the first one to bypass the array
echo "Yes it IS";
} else {
echo "No it's NOT";
}
echo "</div>";
Errors and output:
Array ( [MAX_FILE_SIZE] => 432768 [img_upl_send] => Upload Pictures )
Array ( [0] => [1] => [2] => )
No it's NOT
<form enctype='multipart/form-data' action="ood_images.php?n=y&snd=y&amt=5" method="post" name="imgs_upl"><br /><input type="hidden" name="MAX_FILE_SIZE" value="432768">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr class="top"><td>Picture #</td><td>Select Image</td><td>Main Image?</td></tr>
<tr><td> </td><td> </td><td> </td></tr>
<tr><td>Picture 1:</td><td><input type="file" name="image1" /></td><td><input type="radio" name="main_img" value="1"/></td></tr>
<tr><td>Picture 2:</td><td><input type="file" name="image2" /></td><td><input type="radio" name="main_img" value="2"/></td></tr>
<tr><td>Picture 3:</td><td><input type="file" name="image3" /></td><td><input type="radio" name="main_img" value="3"/></td></tr>
<tr><td> </td><td>Main Picture Already Uploaded:</td><td><input type="radio" name="main_img" value="none"/></td></tr>
<tr><td> </td><td> </td><td><input type="submit" name="img_upl_send" value="Upload Pictures" /></td></tr></table></form>
<?php
define('GW_MAXFILESIZE', 432768);
define('GW_UPLOADPATH', 'test/images/');
if(isset($_POST['submit'])) {
$image = $_FILES['image']['name'];
$image_type = $_FILES['image']['type'];
$image_size = $_FILES['image']['size'];
if(!empty($image)){
if((($image_type == 'image/gif') || ($image_type == 'image/jpeg') ||
($image_type == 'image/pjpeg') || ($image_type == 'image/png')) &&
($image_size >0) && ($image_size <= GW_MAXFILESIZE)) {
if($_FILES['image']['error'] == 0) {
//Move the file to the target upload folder
$target= GW_UPLOADPATH . $image;
if (move_uploaded_file($_FILES['image']['tmp_name'], $target)){
//Confirm success with the user
echo '<p>The following news was added successfully:</p>';
echo '<img src="'.GW_UPLOADPATH . $image . '"alt="New Image" /></p>';
}else{
echo 'Sorry, there was a problem uploading your image.';
}
}
} else{
echo 'The image must be a GIF, JPEG, or PNG image no ' . 'greater than ' . (GW_MAXFILESIZE / 1024) . ' KB in size.';
}
// Try to delete the temporary image file
@unlink($_FILES['image']['tmp_name']);
} else{
echo '<p>Add Your Image</p>';
}
}
?>
<form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="image">Upload Image:</label>
<input type="file" id="image" name="image" />
<input type="submit" value="Post" name="submit" />
define('GW_MAXFILESIZE', 768000);
if((isset($_GET['n'])) || (isset($_POST['new']))) {
if(isset($_POST['img_upl_send'])) {
$amt2upl = $_POST['amt'];
$xu = 1;
$mainimgnum = $_POST['main_img'];
$sn_imgup = $_SESSION['stagename'];
define('GW_UPLOADPATH', $sn_imgup.'/images/');
while($xu <= $amt2upl) {
$image_asso = "image".$xu;
$image = $_FILES[$image_asso]['name'];
$image_tmp = $_FILES[$image_asso]['tmp_name'];
$image_type = $_FILES[$image_asso]['type'];
$image_size = $_FILES[$image_asso]['size'];
if(!empty($image)){
if((($image_type == 'image/gif') || ($image_type == 'image/jpeg') ||
($image_type == 'image/pjpeg') || ($image_type == 'image/png')) &&
($image_size >0) && ($image_size <= GW_MAXFILESIZE)) {
if($_FILES['image']['error'] == 0) {
//Move the file to the target upload folder
$extension = strtolower(substr($image, strrchr($image, ".") + 1));
$cld = generateCode($length=3);
$image2 = $cld.'image'.$extension;
$target= GW_UPLOADPATH . $image2;
if (move_uploaded_file($image_tmp, $target)){
//Confirm success with the user
$Message = "Successfully added ".$amt2upl." images";
// DB INSERTION
}else{
$Message = "Sorry, there was a problem uploading your image.";
exit;
}
}
} else{
$Message = "The image must be a GIF, JPEG, or PNG image no " . "greater than " . (GW_MAXFILESIZE / 1024) . " KB in size.";
exit;
}
// Try to delete the temporary image file
@unlink($img_tmp);
}
$xu++;
}
echo "<div class=\"titlebar\"><strong>".$Message."</strong></div>";
echo "</div></div><div id=\"footer\">";
include("includes/footer.php");
exit;
}