Form Fun!
Posted: Wed Jan 06, 2010 9:34 am
I'm building a submission form for uploading files and storing a name in the database... so far I have gotten it to store the title but nothing else. The files don't even upload.
Form:
PHP:
Form:
Code: Select all
<form method="post" action="upload_process.php" enctype="multipart/form-data">
<p>
Title:
</p>
<input type="text" name="title"/>
<p>
Thumbnail:
</p>
<input type="file" name="thumb">
<p>
EPS 1:
</p>
<input type="file" name="eps1">
<p>
EPS 2:
</p>
<input type="file" name="eps2">
<p>
PDF 1:
</p>
<input type="file" name="pdf1">
<p>
PDF 2:
</p>
<input type="file" name="pdf2">
<br/>
<br/>
<input TYPE="submit" name="upload" title="Add data to the Database" value="Submit"/>
</form>
Code: Select all
<?php
//This is the directory where images will be saved
$target = "/path/to/upload/";
$target = $target . basename( $_FILES['thumb']['thumbName']['eps1']['eps1Name']['eps2']['eps2Name']['pdf1']['pdf1Name']['pdf2']['pdf2Name']);
//This gets all the other information from the form
$title=$_POST['title'];
$thumb=($_FILES['thumb']['thumbName']);
$eps1=($_FILES['eps1']['eps1Name']);
$eps2=($_FILES['eps2']['eps2Name']);
$pdf1=($_FILES['pdf1']['pdf1Name']);
$pdf2=($_FILES['pdf2']['pdf2Name']);
// Connects to your Database
mysql_connect("localhost", "user", "pass") or die(mysql_error()) ;
mysql_select_db("database") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO test (title,thumb,eps1,eps2,pdf1,pdf2)
VALUES ('$title', '$thumb', '$eps1', '$eps2', '$pdf1','$pdf2')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['thumb']['tmp_name']['eps1']['tmp_name']['eps2']['tmp_name']['pdf1']['tmp_name']['pdf2']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The files ". basename( $_FILES['uploadedfile']['thumbname']['eps1Name']['eps2Name']['pdf1Name']['pdf2Name']). " have been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>