File "insert_document01.php"

Full Path: /home/analogde/www/Prog/MMM/Fusion/Document to mysql/insert_document01.php
File size: 2.27 KB
MIME-type: text/x-php
Charset: utf-8

<?php 


$db_host = "analogdepat.mysql.db";
$db_user = "analogdepat";
$db_pass = "Un92pac007";
$db_name = "analogdepat";


$conn = new mysqli($db_host, $db_user, $db_pass, $db_name) or die("Could not connect to mysql".mysqli_error($conn));

echo "plouf.......................";


$filename = "file.pdf";

//echo file_exists($filename);
//$fileSize = $formatFileSize($filename); 
//echo ">>>>> " .$fileSize; 
//$size = filesize($filename);
//echo convert_filesize($size);

$fileType = "pdf/doc";
$fileSize = "1234";
$pdf_content = file_get_contents($filename);
$pdf_content = mysqli_real_escape_string($conn, $pdf_content); 

echo "jkjkljkjkljk";



$query = "INSERT INTO db_document (name, size, type, content ) ".
"VALUES ('$filename', '$fileSize', '$fileType', '$pdf_content')";



//$sql = "INSERT INTO table_name (pdf_column) VALUES ('$pdf_content')";

if ($conn->query($query) === TRUE) 
{
    echo "PDF inserted successfully";
} 
else 
{
    echo "Error inserting PDF: " . $conn->error;
}
//$conn= new mysqli('localhost','root','','house_rental_latest')or die("Could not connect to mysql".mysqli_error($con));

//filesize("test.txt");
/*
$query = "INSERT INTO upload (nom, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysqli_query($con,$query) or die('Error, query failed'); 
mysqli_close($con);
*/
/*
CREATE TABLE IF NOT EXISTS `db_document` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `name` varchar(30) NOT NULL,
    `type` varchar(30) NOT NULL,
    `size` int(11) NOT NULL,
    `content` longblob NOT NULL,
    PRIMARY KEY (`id`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 ;
*/

function human_filesize($bytes, $decimals = 2) {
    $size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
    $factor = floor((strlen($bytes) - 1) / 3);
    return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
}

function formatFileSize($filename) 
{
    $size = filesize($filename);

    $units = array('B', 'KB', 'MB', 'GB', 'TB');
    $formattedSize = $size;

    for ($i = 0; $size >= 1024 && $i < count($units) - 1; $i++) 
    {
        $size /= 1024;
        $formattedSize = round($size, 2);
    }

    return $formattedSize . ' ' . $units[$i];
}

  ?>