$fileCount = count($_FILES);
for ($i = 0; $i < $fileCount; $i++) {
$fp = fopen($_FILES[\"file_\".$i][\'tmp_name\'], \'rb\');
$stmt4 = $dbh - > prepare(\"IN
You can try
MySQL
CREATE TABLE files (
id INT AUTO_INCREMENT PRIMARY KEY,
mime VARCHAR (255) NOT NULL,
data BLOB NOT NULL
);
PHP
class BlobDemo {
const DB_HOST = 'localhost';
const DB_NAME = 'nameofdb';
const DB_USER = 'username';
const DB_PASSWORD = 'password';
/**
* PDO instance
* @var PDO
*/
private $pdo = null;
/**
* Open the database connection
*/
public function __construct() {
// open database connection
$conStr = sprintf("mysql:host=%s;dbname=%s;charset=utf8", self::DB_HOST, self::DB_NAME);
try {
$this->pdo = new PDO($conStr, self::DB_USER, self::DB_PASSWORD);
//for prior PHP 5.3.6
//$conn->exec("set names utf8");
} catch (PDOException $e) {
echo $e->getMessage();
}
}
/**
* insert blob into the files table
* @param string $filePath
* @param string $mime mimetype
* @return bool
*/
public function insertBlob($filePath, $mime) {
$blob = fopen($filePath, 'rb');
$sql = "INSERT INTO files(mime,data) VALUES(:mime,:data)";
$stmt = $this->pdo->prepare($sql);
$stmt->bindParam(':mime', $mime);
$stmt->bindParam(':data', $blob, PDO::PARAM_LOB);
return $stmt->execute();
}
}
$blobObj = new BlobDemo();
// test insert pdf
$blobObj->insertBlob('pdf/prova.pdf',"application/pdf");
work for me,I try with PDF,JPG and HTML for insert update and view.