All pastes #115592 Raw Edit

Anonymous

public text v1 · immutable
·published 2006-08-04 18:37 UTC
rendered paste body
if ($_GET['act'] == "add") {
	echo "
<center><a href='admingallery.php'>Go Back</a></center><br />
<div class='greentext'>To add a photo to your gallery, Fill out the following form below.  A heading and description is needed for the gallery.  When selecting your photo, please note that it will automatically re-size your photo on the gallery.php page, so you may choose the large photo for your gallery.  </div><br /><br />

<div class='blacktext'>
<form method='post' action='admingallery.php?act=added' enctype='multipart/form-data'>
   <table>
	<tr>
	  <td>Picture Heading:</td>
	  <td><input type='text' name='heading'></td>
	</tr>
	<tr>
	  <td>Picture Description:</td>
	  <td><textarea name='description' cols=25 rows=7>Description of Photo</textarea></td>
	</tr>
	<tr>
	  <td>Browse Picture:</td>
	  <td><input type='file' name='picture'></td>
	</tr>
	<tr>
	 <td><input type='submit' value='Add Photo'></td>
	</tr>
   </table>
</form>
";
} else

if ($_GET['act'] == "added") {
	 $uploaddir = $_SERVER['DOCUMENT_ROOT'] . "/galleryimages/";
	 $filename = $_FILES['picture']['name'];
	 $allowed_types = array(
        "image/gif" => "gif",
        "image/pjpeg" => "jpg",
        "image/png" => "png",
        "image/bmp" => "bmp",
        "image/jpeg" => "jpg",
    );
    

    if(!array_key_exists($_FILES['picture']['type'], $allowed_types)) {
        echo "Wrong file type! Please go back and try again.";
    } else
	if(file_exists($uploaddir . $filename)) {
        	echo "File already exists! Please go back and try again.";
        } else
	if (!$_POST['heading'] || !$_POST['description'] || !$_POST['picture']) {
		echo "Field left blank, please go back and try again.";
	} else {
	 copy($file, $uploaddir.$filename) or die("Could not copy image");
	 $sql = "INSERT INTO gallery (id,heading,description,picture) VALUES('','$_POST[heading]','$_POST[description]','$_POST[picture]')";
	 $result = mysql_query($sql);
	 
	 echo "Success!";
}