Loading...
 
Skip to main content

Development


How to get File Galleries info from Database?

Hi everyone,

I'm developing a plugin for running an external application and presenting its output in a user-generated page. However, I'm a complete MySQL newbie and an almost-complete PHP newbie also, so I please ask you bear with me on this... :mrgreen:

I've attempted to look into existing PHP code of Tiki to find out exactly how to get the 'filename', 'galleryId', and 'path' fields from the 'tiki_files' table, but I'm fairly confused at this point. I don't know how Tiki goes about to query this information from the MySQL Database. From this information I plan to give it to the external application the 'path' argument as the filename to process from the tiki_files directory (it runs on the same machine).

Where can I find a template-like plugin to do this, or an approximate example? If neither exist, other ideas are of course welcome.

Thanks in advance! 😀

Hi again,

To reply to my own question, I offer a solution I found after sifting through the Tikiwiki library code. I'm not sure about its efficiency so I ask knowledgeable people to please comment.


Inside a plugin function of named wikiplugin_myplugin($data, $params) I write:
code
global $tikilib;

$gallery = 'MyGallery';
$filename = 'MyFile.txt';

$queryGallery = "select * from tiki_file_galleries where name='".$gallery."'";
$resultGallery = $tikilib->db->query($queryGallery);
$res = $resultGallery->fetchRow();
$galleryId = $res'galleryId';

$queryFilename = "select * from tiki_files where filename='".$filename."' and galleryId='".$galleryId."'";
$resultFilename = $tikilib->db->query($queryFilename);
$res = $resultFilename->fetchRow();
return "MD5: ".$res'path'.".";
/code

This returns the HTML string giving the 32-characters MD5-like filename stored in the /var/lib/tikiwiki_files corresponding to the binary file 'MyFile.txt' uploaded to the Tikiwiki gallery 'MyGallery'. Further exercises are left to the reader 😁 .

Sorry, I meant to say:

Copy to clipboard
global $tikilib; $gallery = 'MyGallery'; $filename = 'MyFile.txt'; $queryGallery = "select * from tiki_file_galleries where name='".$gallery."'"; $resultGallery = $tikilib->db->query($queryGallery); $res = $resultGallery->fetchRow(); $galleryId = $res['galleryId']; $queryFilename = "select * from tiki_files where filename='".$filename."' and galleryId='".$galleryId."'"; $resultFilename = $tikilib->db->query($queryFilename); $res = $resultFilename->fetchRow(); return "MD5: ".$res['path'].".";