Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
174 views
in Q2A Core by
I came across the situation that I am editing an image (a blob) that is already stored on the server (file system or db) and need to update the content of the blob (file system or db).

For the DB I was using:

qa_db_blob_set_content($blobid, $content)

However, for the file system there does not seem to be such an update function (?)

 

PS: qa_write_blob_file() gives me "failed to open stream: File exists"
Q2A version: 1.7.2
by
How were you updating the image originally, when you were using the database? You say you were calling "qa_db_blob_set_content" but was this from a custom plugin?
by
Before all files were stored on DB, now I store them on the file system. Thus I discovered the missing update function.

1 Answer

+1 vote
by
I wrote this function, originated from qa_write_blob_file():

 

        function qa_update_blob_file($blobid, $content, $format)
        /*
            Update the on-disk file for blob $blobid with $content and $format. Returns true if the write succeeded, false otherwise.
        */
        {
            $written = false;

            $directory = qa_get_blob_directory($blobid);
            if (is_dir($directory))
            {
                $filename = qa_get_blob_filename($blobid, $format);

                $file = fopen($filename, 'wa+'); // xb would create a new file, however, we replace it
                if(is_resource($file))
                {
                    if(fwrite($file, $content)>=strlen($content))
                        $written = true;

                    fclose($file);

                    if(!$written)
                        unlink($filename);
                }
            }

            return $written;
        }
...