Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
909 views
in Q2A Core by
edited by
If one wants to write the contents of an image to the database (in the blobs : 'qa_blobs'), how would he do so through PHP?
Q2A version: 1.6.1

2 Answers

+2 votes
by

Look at qa-app-blobs.php and its documentation here.

by
Great document !!
by
I updated this post with code, but it won't work :(! Any ideas?
0 votes
by

In my plugin I use this code to write images to the database : 

//require_once '../../qa-include/qa-base.php';
require_once '../../qa-include/qa-app-blobs.php';
 
$p = $_POST;
$allowedTypes = array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF);
$id=0;
foreach($_FILES as $f) { 
    $detectedType = exif_imagetype($f['tmp_name']);
    if(in_array($detectedType, $allowedTypes)){
        $pi = pathinfo($f['name']);
        $name = $f['tmp_name'];
        $ext = $pi['extension'];
        //move_uploaded_file($f['tmp_name'], '');
       if (qa_write_blob_file($id++, file_get_contents($name), $ext)) echo qa_get_blob_url($id,true);
else echo "error";
}
However, this does not work. Is there something I do wrong?
by
You should be using qa_create_blob(...) not qa_write_blob_file(...) - please read the documentation page whose link I provided.
...