Here’s my function:
function process_image($path) {
global $mysqli;
list($width,$height) = getimagesize($path);
$hash = md5_file($path,true);
$pic = $mysqli->prepare('INSERT INTO pictures () VALUES ()');
$pic->execute();
$pic_id = $pic->insert_id;
$size = $mysqli->prepare("INSERT INTO picture_sizes (filename, type, picture_id, hash, width, height) VALUES (?,'FULL',?,?,?,?)");
$size->bind_param('sibii',$path,$pic_id,$hash,$width,$height);
if(!$size->execute()) {
echo $size->error.'<br/>';
}
}
The ‘hash’ field always shows up as 0s in my database. I’ve got it set to BINARY(16). I’m guessing I’m using $size->bind_param incorrectly, but I can’t figure out how to do it properly. $hash is binary, so I should be using b with it, no?
In case of an error, md5_file returnsfalse, which is converted to0when stored in the database. Check if the function returns false using the===operator.Because the hash is a string, you can make the parameter of the type
s(string).