this simple code generated here (there is video tutorial over there)
you've got an upload folder.
you fill the form, and post it.
if(!empty($_POST["submit"]))
{
*1 do something...
}
lets check the required fields, and build an error array..
*1:
if(empty($_FILES["f_fileup"]["tmp_name"]))
$error[]="fileup is a required field."; // Check if fileup is empty.
if(empty($_POST["f_one_field"]))
$error[]="one_field is a required field."; // Check if one_field is empty.
check if the $error array has values, if yes, print it in other case upload the files and fill the table with data.
if(empty($error))
{
if(!empty($_FILES["f_fileup"]["tmp_name"]))
{
move_uploaded_file($_FILES["f_fileup"]["tmp_name"] , "uploads/".basename($_FILES["f_fileup"]["name"])) OR die("Could not upload");
$f_fileup= mysql_real_escape_string(basename($_FILES["f_fileup"]["name"]));
}
$f_one_field=mysql_real_escape_string($_POST["f_one_field"]);
$sql="INSERT INTO table (`fileup`,`one_field`) VALUES ('$f_fileup','$f_one_field') ";
mysql_query($sql) or die(mysql_error());
header("Location: uploaded.html");
}
else
print "Please check these errors:<br />" . implode("<br />" , $error);
the file uploaded into the upload folder, and basename will create a file name without the original folder name. The file name will be included into the table. If you need to make a link for that file, you get the file name from this table, and use the upload folder as folder name.
got question?