Hi,
Here is a form that will upload a picture to where I want it and it will also insert it into my database, if I wanted to add another file field in the form for people to upload a pdf as well as the other image how would you go about it?
$page_title = 'Upload a File';
if (isset($_POST['submit'])) { // Handle the form.
require_once ('./mysql_connect.php'); // Connect to the database.
// Function for escaping and trimming form data.
function escape_data ($data) {
global $dbc;
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string (trim ($data), $dbc);
} // End of escape_data() function.
$pics_thumburl = "uploads/".$_FILES['upload']['name'];
// Add the record to the database.
$query = "INSERT INTO woodman ( pics_thumburl, registration_date) VALUES ('$pics_thumburl', NOW())";
$result = @mysql_query ($query);
if ($result) {
// Create the file name.
$extension = explode ('.', $_FILES['upload']['name']);
$uid = mysql_insert_id(); // Upload ID
$filename = $_FILES['upload']['name'];
// Move the file over.
if (move_uploaded_file($_FILES['upload']['tmp_name'], "./uploads/$filename")) {
echo '<p>The file has been uploaded!</p>';
} else {
echo '<p><font color="red">The file could not be moved.</font></p>';
// Remove the record from the database.
$query = "DELETE FROM woodman WHERE upload_id = $uid";
$result = @mysql_query ($query);
}
} else { // If the query did not run OK.
echo '<p><font color="red">Your submission could not be processed due to a system error. We apologize for any inconvenience.</font></p>';
}
mysql_close(); // Close the database connection.
} // End of the main Submit conditional.
Here is the form to go with it,
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="524288">
<fieldset><legend>Fill out the form to upload a file:</legend>
<p><b>File:</b> <input type="file" name="upload" /></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Submit" /></div>
</form><!-- End of Form -->
Thank you in advance as always.
Phil