I am now trying to model the upload on what was done for Ninja Forms. This is what I have tried:
function action_getmsgup($uploadid) {
global $wpdb, $out;
$query = $wpdb->prepare("SELECT ID, post_mime_type, guid FROM {$wpdb->prefix}posts WHERE ID = %d", array($uploadid));
$rows = $wpdb->get_results($query, ARRAY_A);
foreach ($rows as $row) {
$url = $row['guid'];
$filename = basename($url);
$path = parse_url($url, PHP_URL_PATH); // just the path part of the URL
$parts = explode('/', $path); // all the components
$parts = array_slice($parts, -6); // the last six
$path = implode('/', $parts);
$filepath = ABSPATH . $path;
$contents = file_get_contents($filepath);
if ($contents === false) {
$out['errmsg'] = "Unable to read \"$filepath\"";
return;
}
$out['filename'] = $filename;
$out['mimetype'] = $row['mimetype'];
$out['datetime'] = $row['post_date'];
$out['contents'] = base64_encode($contents);
}
}
Still I am just getting the upload of the file and it will not show up in the object viewer. I have also tried it without the base64_encode and still no object viewer is responding. The good news is the upload works with file_get_contents() now.