For some reason when I upload a document and store the file name in mysql table the file name extension isn't included in the name. For example, I upload the pdf file "car.pdf" and the way it is stored in mysql table is "car."(see period right after the word, The file extension is not included). I have checked this website, I have googled it too, but can't find a clear answer.
$doc_name = mysqli_real_escape_string($dbc, trim($_FILES['doc']['name']));
$doc_type = $_FILES['doc']['type'];
$doc_size = $_FILES['doc']['size'];
if(!empty($title)){
if(!empty($doc_name)){
if (($doc_type == 'application/pdf') || ($doc_type == 'application/msword') || ($doc_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')){
if(($doc_size > 0) && ($doc_size <= FILE_MAXFILESIZE)){
if ($_FILES['doc']['error'] == 0) {
$final_name = time() . $doc_name;
$target = $uploadpath . $final_name;
if(move_uploaded_file($_FILES['doc']['tmp_name'], $target)) {
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die ('There was a problem with your query. Please, contact administrator');
if(!empty($description)){
$query = "INSERT INTO uploaded_files (file, title, description, date_time, user_id, dep_id) VALUES ('$final_name', '$title', '$description', now(), '" . $_SESSION['user_id'] . "', '$dep_id')";
}.... rest of the code goes here
MySQL could truncate the string you're inserting, if the length of the string exceeds what you have in the column definition. In this case, check that the file path name does not have a string name longer than 32.
Ordinarily, one would expect this INSERT query to fail, but it may not do so if the configuration settings permit.
If the mysql configuration is under your control (and you desire to avoid this kind of silent truncation of inserted string), start by adding strict_trans_tables
to the sql_mode
settings in your my.ini
(OR my.conf
) file.
Best of luck.