function file_upload() { // init response $response = array('status' => 'error', 'message' => __('file upload failed', 'mgm')); // upload, using helper if ($file_info = mgm_save_file_for_download('download_file')) { // response $response = array('status' => 'success', 'message' => __('file uploaded successfully, it will be attached when you save the data.', 'mgm'), 'file_info' => $file_info); } // send ouput @ob_end_clean(); // print echo json_encode($response); // end out put @ob_flush(); // exit exit; }
/** * update download * * @param none * @return download * @verb POST * @action update * @url <site>/mgmapi/downloads/update.<format> * @since 1.0 */ public function update_post() { // post vars $post_vars = $this->request->data['post']; // status $status = 'error'; $data = array(); // message $message = __('Download update failed, ', 'mgm'); // save if (!($errors = $this->_validate_data('update', $post_vars))) { // id $id = (int) $post_vars['id']; // title if (isset($post_vars['title'])) { $data['title'] = trim($post_vars['title']); } // file url if (isset($post_vars['file_url'])) { // name $data['filename'] = $post_vars['file_url']; // real name $data['real_filename'] = basename($post_vars['file_url']); } else { // try upload if ($file_info = mgm_save_file_for_download('file_name')) { // name $data['filename'] = $file_info['file_url']; // real name $data['real_filename'] = $file_info['real_name']; } } // expire date if (isset($post_vars['expire_dt'])) { $data['expire_dt'] = $post_vars['expire_dt']; } // members_only if (isset($post_vars['members_only'])) { $data['members_only'] = $post_vars['members_only']; } // user_id if (isset($post_vars['user_id'])) { $data['user_id'] = $post_vars['user_id']; } // posts $posts = isset($post_vars['posts']) && is_array($post_vars['posts']) ? $post_vars['posts'] : NULL; // update if ($download = mgm_update_download($id, $data, $posts)) { // status $status = 'success'; // message $message = __('Download updated successfully', 'mgm'); // data $data = array('download' => $download); } else { $message .= __('Database error', 'mgm'); } } // response $response = array('status' => $status, 'message' => $message, 'data' => $data); // errors if ($errors !== FALSE) { $response = $response + array('errors' => $errors); } // return return array($response, 200); }