How to get the 'system_path' value after uploadMany
How to get the 'system_path' value after uploadMany
Hi All,
I am using the php libraries. I have followed the uploadMany example at "/examples/advanced/upload-many.html" and it works as I want.
After the form is submitted I am running a function via the ->on('postCreate') method:
->on( 'postCreate', function ( $editor, $id, $values, $row ) {
qEmails( $editor->db(), $id, $values, $row );
} )
The $row array contains a nested array of the "id"(s) of my uploaded file(s), eg: "files":[{"id":"2"},{"id":"3"}]}],
I now need to get the 'system_path' value which is held in the files table.
Is the 'system_path' value available already or do I need to query the table?
I've tried:
function qEmails ( $db, $id, $values, $row ) {
$resultset = array();
for ($x=0; $x < count($row["files"]); $x++) {
$y = $row["files"][$x]["id"];
$results = $db->raw()
->bind(':enrid', $y)
->exec("SELECT system_path FROM files WHERE id = :enrid");
foreach($results['data'] as $result) { //not sure of this syntax
$resultset[] = $result['system_path']; //not sure of this syntax
}
}
$qAttachments = json_encode($resultset);
...
}
without success. Any help would be appreciated.
One more point of discussion:
When I return the data for a single user record from uploadMany.php it contains a huge list of every file that has been uploaded in connection with this table. The documentation doesn't really explain how this is useful. Is it not a performance hit to return so much 'un-requested' data from a table with many records?
Brendon
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Replies
Hi Brendon,
Assuming you are using the
Upload->db()
method then it should be in the$row
parameter. Exactly where will depend upon your configuration. If you dofile_put_contents( '/tmp/editor-upload', print_r( $row, true ) );
it will dump the$row
parameter into the file specified so you could have a look at the data structure to know where to get that data.It isn't. Its almost but not quite a bug (since it is working as I currently designed it - the bug is in the design of that aspect!). This will change with 1.6 which will be released later this summer.
Allan
Thanks for the reply Allan.
I am using the uploadMany example as given. I think it uses the upload->db method:
I tried printing out the $row var but unfortunately it only contains the id from the files table.
I also printed out the $values array but the 'system_path' is not there either.
In my previous post, do I have the right syntax to handle the results of $db->raw() ?
Brendon
Ah - yes, sorry, I was mistaken this morning (I was thinking about left joins). You are correct that you would need to query the database based on the id to get the meta information about the file.
Yes, but you need to get the results:
You could also use the
select
method rather thanraw()
.Allan
Many thanks Allan.