Location: PHPKode > projects > ProPHP > ProPHP/content/ad_options/add.php
<?php
	/*****************************************************************
	************* BKWORKS PRO PHP V 0.5 BETA 1 ***********************
	******************** BRYAN KOOIENGA ******************************
	****************** DECEMBER 20, 2007 ****************************
	*****************************************************************/

if(defined("INDEX")) { # If the index is calling the script then
	if(!isset($_SESSION['user'])) { # If the user isn't logged in, then show the logon page
		include("content/homepage/index.php");
	} else { # Otherwise, the user is logged in.
		$username = $_SESSION['user']; # Set our working variable to the session variable.
		if($_POST) { # If the form has been submitted
			$query = "SELECT site_number FROM sites WHERE site_url = '$username'"; # Get the user ID from the database.
			$results = mysql_query($query) or die("Can't query because " . mysql_error());
			$results = mysql_fetch_object($results);
			$site_number = $results -> site_number;
			
			if($_POST['size'] !=  "") { # If the size was selected then
				if($_POST['url'] != "") { # If the URL for the ad was entered then
					if($_FILES['image']['name'] != "") { # If an ad was uploaded
						if($_FILES['image']['size'] <= 250000) { # If the size was less than 250 KB
							$type = $_FILES['image']['type']; # Now, we're going to check for the type of image uploaded
							$type = strtolower($type);
							if($type == "image/jpeg" OR $type == "image/pjpeg" || $type=="image/gif" || $type=="image/pgif") { # Only allowed types are Jpegs and Gif images. Because IE likes to be independant, we have to add "p" to every filetype.
								$randomit = rand(1,600);
								$filename = md5($randomint); # Just to add a litle fun, and to prevent duplicate filenames
								$filename .= basename($_FILES['image']['name']);
								// echo $filename;
								$tmpname = $_FILES['image']['tmp_name'];
								echo "Temp Name: $tmpname<br>\n";
								move_uploaded_file($tmpname,"ads/$site_number/$filename"); # Moves the uploaded file
								if($_POST['size'] == "468-60") {
									$size['width'] = "468";
									$size['height'] = "60";
								} elseif($_POST['size'] == "120-240") {
									$size['width'] = "120";
									$size['height'] = "240";
								} else {
									$size['width'] = "120";
									$size['height'] = "600";
								}
								$query = "INSERT INTO ads(
									site_number,
									width,
									height,
									image,
									alt_text,
									ad_goto
								) VALUES (
									'$site_number',
									'$size[width]',
									'$size[height]',
									'$filename',
									'$_POST[alt]',
									'$_POST[url]'
								)";
								mysql_query($query) or die("Can't query because " . mysql_error());
								echo ("Your ad  was added successfully!");
							} /* TYPE */ else {
								$error = "Invalid Image Type. Currently, we only accept <b>JPEG</b> or <b>GIF</b> images.";
							}
						} /* image size */ else {
							$error = "Invalid Image Size. Currently, our images can be 250 KB at most.";
						}
					} /* image at all? */ else {
						$error = "Invalid Image Name. It's possible you didn't chose an image at all.";
					}
				} /* URL! */ else {
					$error = "You didn't enter a URL for the ad to point to!";
				}
			} /* size */ else {
				$error = "Invalid Advertisement Size! You must choose how large your ad is!";
			}
		}
		?>
	<h3>Add a new advertisement</h3>
	<p>To add a new advertisement to your account, please fill in all of the information below. </p>
	<form action="" method="post" enctype="multipart/form-data">
	<table width="100%">
		<?php
			if(isset($error)) {
				echo "<tr>
					<td align=\"right\"><b>Errors:</b></td>
					<td>$error</td>
				</tr>";
			} ?>
		<tr>
			<td align="right" width="20%">Ad Size:</td>
			<td><select name="size">
				<option value="">Select an ad size</option>
				<option value="468-60">468 X 60</option>
				<option value="120-240">120 X 240</option>
				<option value="120-600">120 X 600</option>
			</select></td>
		</tr>
		<tr>
			<td align="right">Link URL:</td>
			<td><input type="text" name="url" /></td>
		</tr>
		<tr>
			<td align="right">Select an image:</td>
			<td><input type="file" name="image" /></td>
		</tr>
		<tr>
			<td align="right">Alternate text:<br />
			(for browsers that don't support images)</td>
			<td><input type="text" name="alt" /></td>
		</tr>
		<tr>
			<td align="right"><input type="submit" value="Add this ad" name="submitbutton" /></td>
		</tr>
	</table>
	</form>
	<?php
	}
} else { # not being called by the index. Let's go to the logon screen.
	header("location: ../../?view=home");
}
?>
Return current item: ProPHP