Kudos to all ,
I am trying to facilitate the process of importing some jpg files I have into a blob field on MySQL. I wanted to get the filename and blob, however, I am encountering a wall when attempting to read the files into my database. Any help is appreciated. Below is the code I have been manipulating to no avail.
<?php
mysql_connect ("localhost","root");
mysql_select_db("sou");
$dirPath = "\relative\path\to\files";
$handle=opendir($dirPath);
while (false!==($file = readdir($handle))) {
if ($file != "." && $file != "..") {
writeToBlob($file, $dirPath);
}
}
closedir($handle);
function writeToBlob($file, $dirPath) {
// Read File
$newHandle = fopen($dirPath . "/" . $file, "rb");
$contents = fread ($newHandle, filesize ($dirPath . "/" . $file));
fclose($newHandle);
// Write it to the DB
$sql = "INSERT INTO img (filename, photo) values ('".$contents_name."','".$contents."')";
mysql_query($sql);
$id=mysql_insert_id();
}
?>