Hi all,
I have an upload script, it should move the selected file to the specified server location and then add the attributes i.e file size, name, upload date onto my MySQL database. For some reason I cannot get it to work, I thought I had it working correctly but cannot get back to this stage.
My form code is:-
[php]
Title of the File
File Category
and my upload script is:-
[php]<?php
if($_POST)
{
if(!isset($_POST[‘file_title’]) || strlen($_POST[‘file_title’])<1)
{
//required variables are empty
die(“File Title is empty! please go back and enter”);
}
if($_FILES['file_name']['error'])
{
//File upload error encountered
die(upload_errors($_FILES['file_name']['error']));
}
//This is the directory where images will be saved
$target = “uploads/”;
$target = $target . basename( $_FILES[‘file_name’][‘name’]);
//This gets all the other information from the form
$file_name = basename( $_FILES[‘file_name’][‘name’]);
$file_size = $_FILES[‘file_name’][“size”];
$file_title = $_POST[‘file_title’];
$client_id = $_POST[‘client_id’];
$file_cat = $_POST[‘file_cat’];
$file_type = $_FILES[‘file_name’][‘type’];
$uploaded_date = date(“Y-m-d H:i:s”);
//Writes the Filename to the server
if(move_uploaded_file($_FILES[‘file_name’][‘tmp_name’], $target)) {
//Tells you if its all ok
echo "The file “. basename( $_FILES[‘file_name’][‘name’]). " has been uploaded, and your information has been added to the directory”;
// Connects to database
include(’…/includes/mysqli_connect.php’);
if (mysqli_connect_errno($db)) {
trigger_error('Database connection failed: ’ . mysqli_connect_error(), E_USER_ERROR);
}
// add file details to database
$query = “INSERT INTO tbl_documents (file_name,file_title,file_size,client_id,file_typ,uploaded_date,file_cat) VALUES (’$file_name’,’$file_title’,’$file_size’,’$client_id’,’$file_typ’,’$uploaded_date’,’$file_cat’)”;
$result = mysqli_query($db, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($db), E_USER_ERROR);
} else {
// gives an error if its not uploaded
echo “Sorry, there was a problem uploading your file.”;
}
}
?>[/php]
The only error I receive is the one at the bottom of the script “Sorry, there was a problem…”