Here's the code: (not the whole thing, but the important part)
Code: Select all
<?
require_once('mysqli_connect.php');
$today = date("m-d-Y");
if (isset($_POST['submit'])) { // Handle the form.
if (isset($_FILES['image1'])) {
$allowed = array('image/pjpeg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png');
if(in_array($_FILES['image1']['type'], $allowed)) {
if (move_uploaded_file($_FILES['image1']['tmp_name'], "uploads/riderimages/{$_FILES['image1']['name']}")) {
/************* EVERYTHING IS GOOD TO GO ****************/
echo 'Great!';
/*$q = "INSERT INTO users (email, pass, username, active, barn_name, registration_date) VALUES ('$e', SHA1('$p'), '$un', '$a', '$bn', NOW() )";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.
echo '<p>Thanks! You\'ve been added!</p>';
echo '<p>Go to the <a href="viewriders.html" alt="View Riders">riders</a> page.</p>';
} else {
echo '<p>There was a problem adding you to the rider database. Try again or contact Caroline.</p>';
}*/
} else {
echo '<p class="error">There was an error uploading your first image. Please contact Caroline.</p>';
}
} else { //not a valid type
echo '<p class="error">Sorry, that\'s not a valid image type. Please use only JPEG or PNG.</p>';
}
} else { //there isnt anything in image1
echo '<p class="error">Please upload two image files.</p>';
}
}//submitted
if (file_exists($_FILES['image1']['tmp_name']) && is_file($_FILES['image1']['tmp_name']) ) {
unlink ($_FILES['image1']['tmp_name']);
}
?><title>Untitled Document</title>
<div id="textcontainer">
<h1>Add A Rider</h1>
<form action="" method="post" enctype="multipart/form-data">
<table>
<tr><td style="text-align:right">Image one:</td><td><input type="file" name="image1" id="image1" /></td></tr>
<tr><td style="text-align:center" colspan="2"><input type="submit" name="submit" id="submit" value="Add" /></td></tr>
</table>
</form>
</div>
Also, as a side note, how would I store the image file in the database? Would I use $_FILES['image1']['name'] ?