BlackNovaDesigns-Kyle Posted March 26, 2018 Share Posted March 26, 2018 I currently have taken on the old WHMCS CMS Plus add-on and is no longer developed. However - I am now re-writing it to have some new features, but need struggling to add a Database Upload Image function (stores Image URL in database), just wanted to know if anyone had done an image upload function before, I've written image uploads before but never in WHMCS so getting a little confused. Anyone have any ideas? Here is my current code but not sure if to wrap the Image Upload bit in a function, but how to then reference it in the hook? //Image Upload for Featured Image // Set Target Path for file upload $target_path = '../images/'. date("Y") . '/' . date("m") .'/'; if (!file_exists($target_path)) { mkdir($target_path, 0777, true); } if (!file_exists($target_path . 'thumbnails/')) { mkdir($target_path . 'thumbnails/', 0777, true); } //Valid Extensions $validextensions = array( 'image/pjpeg' => 'jpg', 'image/jpeg' => 'jpg', 'image/gif' => 'gif', 'image/bmp' => 'bmp', 'image/x-png' => 'png', 'image/png' => 'png' ); //File Names $simpleName = $_POST['settings']['fimage']; $filename = rand().$_POST['settings']['fimage']; if (in_array($file_extension, $validextensions) && is_writable($target_path)) { if (move_uploaded_file($_POST['settings']['fimage'], $target_path) ) { // If file moved to uploads folder. $message .= '<li class="succes">'.$simpleName.' uploaded successfully!.</li>'; } else { // If File Was Not Moved. $message .= '<li class="error">'.$simpleName.' Failed to Upload - please try again!.</li>'; }} else { // If File Size And File Type Was Incorrect. $message .= '<li class="error">***Invalid file Size or Type***</li>'; } add_hook('cms/admin/page/edit', 1, 'cms_edit_admin_page_html'); function cms_edit_admin_page_html($vars, $target_path, $filename){ ob_start(); $values = json_decode(json_encode(Capsule::table('mod_whmcs_cms_plus_content')->where('id', $_GET['id'])->first()), true); $type = json_decode(json_encode(Capsule::table('mod_whmcs_cms_plus_content_types')->where('type', $values['type'])->first()), true); if(!empty($_POST['postaction']) && $_POST['postaction'] == 'edit_content'){ $slug = cms_sanitize_string($_POST['settings']['slug']); $meta = array(); foreach($_POST['settings']['meta'] as $key => $value){ if($value['key'] != ''){ $meta[$value['key']] = $value['value']; } } update_query('mod_whmcs_cms_plus_content', array( 'parent' => cms_insert_int(trim($_POST['settings']['parent'])), 'title' => trim($_POST['settings']['title']), 'slug' => $slug, 'fimage' => $target_path.$filename, 'content' => trim($_POST['settings']['content']), 'head_content' => trim($_POST['settings']['head_content']), 'comments' => cms_insert_int($_POST['settings']['comments']), 'fb' => cms_insert_int($_POST['settings']['fb']), 'twitter' => cms_insert_int($_POST['settings']['twitter']), 'gplus' => cms_insert_int($_POST['settings']['gplus']), 'published' => cms_insert_int($_POST['settings']['published']), 'updated' => date("Y-m-d H:i:s"), 'ssl' => cms_insert_int($_POST['settings']['ssl']), 'private' => cms_insert_int($_POST['settings']['private']), 'restrictions' => serialize($_POST['settings']['restrictions']), 'breadcrumbs' => cms_insert_int($_POST['settings']['breadcrumbs']), 'meta' => serialize($meta) ), array( 'id' => $_GET['id'] )); $type = json_decode(json_encode(Capsule::table('mod_whmcs_cms_plus_content_types')->where('type', $values['type'])->first()), true); run_hook('cms/content/edit', array_merge($vars, array('id' => $_GET['id'], 'type' => $type))); $values = json_decode(json_encode(Capsule::table('mod_whmcs_cms_plus_content')->where('id', $_GET['id'])->first()), true); echo '<div class="successbox"><strong><span class="title">'.$vars['_lang']['content_updated'].'</span></strong></div>'; } echo cms_display_form(cms_content_fields($vars, $type, $values['id']), $values, $vars['modulelink'].'&tab=edit&id='.$_GET['id'].'', $vars, array('postaction' => 'edit_content')); return ob_get_clean(); } Thanks Kyle Link to comment Share on other sites More sharing options...
BlackNovaDesigns-Kyle Posted March 26, 2018 Author Share Posted March 26, 2018 Never Mind i have now fixed this and got it all working. Link to comment Share on other sites More sharing options...
Recommended Posts