0

Good Day. So i am struggling with inserting a blob into a mySQL DB that is being sent from a form. in any case it fails on insert and i receive this screen when i use the var_dump to view the $sql variable. My final point of this is to insert a file of any type into the db, regardless of size. Please note that i am trying to do be able to do this with any file type (zip, docx or otherwise).

Output when i run the import

here is my form

<form name="frmImage" enctype="multipart/form-data" action="upload.php"method="post" >
    <label>Upload File:</label><br /> 
    <input autocomplete="off" type="text" id="notes" style="width:50%" name="notes" placeholder="Write Something about this upload">
    <input id="myfile" name="myfile" type="file"/> 
    <button style="width:20%" id="sendFile" name="sendFile" type="sendFile" value="sendFile">Submit</button>
</form>

and here is the PHP script that handles the input from the form.

<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 'On');  //On or Off

 session_start();
 require_once('connect.php');

    if (isset($_POST['sendFile'])) {

            $imgData = ($_FILES['myfile']['tmp_name']);
            $imageProperties = getimageSize($_FILES['myfile']['tmp_name']);
            $notes = mysqli_real_escape_string($connection,$_POST['notes']);
            $email = mysqli_real_escape_string($connection, $_SESSION['email']);
            $comentity = mysqli_real_escape_string($connection,$_SESSION['entityname']);
            $file_size = $_FILES['myfile']['size'];

            $sql = "INSERT INTO `supportcontent` (`sentity`,`scontentdata`, `scontentnotes`, `suseremail`, `stype`,`ssize`)
            VALUES('$comentity', '".file_get_contents($imgData)."','$notes','$email','{$imageProperties['mime']}','$file_size')";

            var_dump($sql);
            $current_id = mysqli_query($connection, $sql) 
            or die("<b>Error:</b> Problem on Image Insert<br/>" . mysqli_error($connection));
            if (isset($current_id)) {
                header("Location: landingpage.php?upload=success");
            }               
        exit();
    }
    else{
        echo 'pedestrian';
    }

?>

So i am not sure whats wront, i am aware the issue is happening in my insert, but i am not exactly sure what could be causing it.

Ashley Nesh
  • 95
  • 1
  • 2
  • 9

2 Answers2

-1

You might want to try the base64_encode function according to this answer: Error in SQL syntax when trying to upload image to BLOB field

-2

I had the same issue once but this code worked fine on me: Remember to change the column that stores the file to longblob