Hi
Firstly I must appologise for duplicating this post, but my earlier one was answered but not resolved.
Basically I want to upload a photo and a pdf into my server and have the links to these files inserted into my database, could anyone help me with this?
I have a script to upload the first one, but to add a second is proving more difficult. I will look forward to any replies.
Thank you as always.
Phil
Here is the script and form for my single image
// This page allows users to upload files to the server.
// Set the page title and include the HTML header.
$page_title = 'Upload a File';
if (isset($_POST['submit'])) { // Handle the form.
require_once ('./mysql_connect.php'); // Connect to the database.
$message = NULL;
// 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.
// Check for a property type.
if (!empty($_POST['type'])) {
$t = escape_data($_POST['type']);
$message .= '<p>You forgot to enter the property type!</p>';
} else {
$t = '';
}
// Check for a location.
if (!empty($_POST['location'])) {
$l = escape_data($_POST['location']);
$message .= '<p>You forgot to enter your location!</p>';
} else {
$l = '';
}
// Check for a price.
if (!empty($_POST['price'])) {
$p = escape_data($_POST['price']);
$message .= '<p>You forgot to enter the price!</p>';
} else {
$p = '';
}
// Check for a reference.
if (!empty($_POST['ref'])) {
$r = escape_data($_POST['ref']);
$message .= '<p>You forgot to enter the reference!</p>';
} else {
$r = '';
}
$pics_thumburl = "uploads/".$_FILES['upload']['name'];
// Add the record to the database.
$query = "INSERT INTO woodman (type, location, price, ref, pics_thumburl, registration_date) VALUES ('$t', '$l', '$p', '$r', '$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.
and here is the form.
<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>
<p><b>Property Type:</b> <input name="type" type="text" id="type" value="<?php if (isset($POST['type'])) echo $POST['type']; ?>" size="15" maxlength="15" />
</p>
<p><b>Location:</b> <input name="location" type="text" id="location" value="<?php if (isset($POST['location'])) echo $POST['location']; ?>" size="15" maxlength="15" />
</p>
<p><b>Price:</b> <input name="price" type="text" id="price" value="<?php if (isset($POST['price'])) echo $POST['price']; ?>" size="15" maxlength="15" />
</p>
<p><b>Reference:</b> <input name="ref" type="text" id="ref" value="<?php if (isset($POST['ref'])) echo $POST['ref']; ?>" size="15" maxlength="15" />
</p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Submit" /></div>
</form><!-- End of Form -->