Just to first clarify, I know there are better ways to do this, but I'm determined to experiment.
Basically, I'm trying to grab an image from a form post, then send that into a database MEDIUMBLOB field.
Unfortunately, using my current method, the end result in the database column is always zero bytes.
phpMyAdmin Screenshot
Here is the code for the image upload on the form:
input type="file" name="_imagePost">
Here is the PHP code on the page, I'm using MySQLi :
if(isset($_POST['_imagePost']))
{
$_useImagePost = 1;
$_imagePost = file_get_contents($_FILES['_imagePost']);
// Open DB Connection
$_conn = databaseConnect();
$_stmt = $_conn->prepare("INSERT INTO Question (Question_Type, Question_Text, Question_Answer, Question_UseImage, Question_Image) VALUES (?, ?, ?, ?, ?)");
$_stmt->bind_param("sssib", $_typePost, $_textPost, $_answerPost, $_useImagePost, $_null);
$_stmt->send_long_data(4,$_imagePost);
$_stmt->execute();
// Close DB Connection
$_conn->close();
}
What I am unsure of is if "isset($_POST['_imagePost'])" works when the input type is file.
What I am sure of, however, is that the current setup doesn't work at all.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…