[ad_1]
I am hoping to get a hand from someone. What I am trying to achieve is a PHP script that will read from a folder, grab the image file located in there and saving it to MYSQL.
So far this is my script (saving, but image file is not being save properly or corrupted)
function saveImage($site, $img){
$filePath = "/home/".$site."/".$img;
$fileType = pathinfo($filePath, PATHINFO_EXTENSION);
$allowTypes = array('jpg','png');
if(in_array($fileType, $allowTypes)){
$fp = fopen($filePath, 'rb');
$conn = OpenCon();
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else
{
$insert = $conn->query("INSERT INTO images(imageID, imagfile) VALUES (NULL, '$fp')");
if($insert){
$status="success";
$statusMsg = "File uploaded successfully.";
}
else{
$statusMsg = $insert;
}
}
}
// Display status message
echo "status:: ";
echo $statusMsg;
}
[ad_2]