Exemplo n.º 1
0
function fre_upload_file()
{
    $res = array('success' => false, 'msg' => __('There is an error occurred', 'theme-backend'), 'code' => 400);
    // check fileID
    if (!isset($_POST['fileID']) || empty($_POST['fileID'])) {
        $res['msg'] = __('Missing image ID', 'theme-backend');
    } else {
        $fileID = $_POST["fileID"];
        $imgType = $_POST['imgType'];
        // check ajax nonce
        if (!de_check_ajax_referer('file_et_uploader', false, false) && !check_ajax_referer('file_et_uploader', false, false)) {
            $res['msg'] = __('Security error!', 'theme-backend');
        } elseif (isset($_FILES[$fileID])) {
            // handle file upload
            $attach_id = et_process_file_upload($_FILES[$fileID], 0, 0, array('jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'bmp' => 'image/bmp', 'tif|tiff' => 'image/tiff', 'pdf' => 'application/pdf', 'doc|docx' => 'application/msword', 'odt' => 'application/vnd.oasis.opendocument.text', 'zip' => 'application/zip', 'rar' => 'application/rar'));
            if (!is_wp_error($attach_id)) {
                try {
                    $attach_data = et_get_attachment_data($attach_id);
                    $options = AE_Options::get_instance();
                    // save this setting to theme options
                    // $options->$imgType = $attach_data;
                    // $options->save();
                    /** 
                     * do action to control how to store data
                     * @param $attach_data the array of image data
                     * @param $request['data']
                     * @param $attach_id the uploaded file id
                     */
                    //do_action('ae_upload_image' , $attach_data , $_POST['data'], $attach_id );
                    $res = array('success' => true, 'msg' => __('File has been uploaded successfully', 'theme-backend'), 'data' => $attach_data);
                } catch (Exception $e) {
                    $res['msg'] = __('Error when updating settings.', 'theme-backend');
                }
            } else {
                $res['msg'] = $attach_id->get_error_message();
            }
        } else {
            $res['msg'] = __('Uploaded file not found', 'theme-backend');
        }
    }
    // send json to client
    wp_send_json($res);
}
Exemplo n.º 2
0
 /**
  * update branding : logo, mobile icon
  */
 function upload_image()
 {
     global $user_ID;
     $res = array('success' => false, 'msg' => __('There is an error occurred', 'aecore-class-ae-page-backend'), 'code' => 400);
     /**
      * User must login to upload image
      */
     if (!$user_ID) {
         $res['msg'] = __("You must login to upload image.", 'aecore-class-ae-page-backend');
         wp_send_json($res);
     }
     // check fileID
     if (!isset($_POST['fileID']) || empty($_POST['fileID']) || !isset($_POST['imgType']) || empty($_POST['imgType'])) {
         $res['msg'] = __('Missing image ID', 'aecore-class-ae-page-backend');
     } else {
         $fileID = $_POST["fileID"];
         $imgType = $_POST['imgType'];
         // check ajax nonce
         if (!de_check_ajax_referer($imgType . '_et_uploader', false, false) && !check_ajax_referer($imgType . '_et_uploader', false, false)) {
             $res['msg'] = __('Security error!', 'aecore-class-ae-page-backend');
         } elseif (isset($_FILES[$fileID])) {
             //
             $upload_mimes = apply_filters('et_upload_file_upload_mimes', array('jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'bmp' => 'image/bmp', 'tif|tiff' => 'image/tiff', 'doc|docx' => 'application/msword', 'ppt' => 'application/vnd.ms-powerpoint', 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation'));
             // handle file upload
             $attach_id = et_process_file_upload($_FILES[$fileID], 0, 0, $upload_mimes);
             if (!is_wp_error($attach_id)) {
                 try {
                     $attach_data = et_get_attachment_data($attach_id);
                     $options = AE_Options::get_instance();
                     // save this setting to theme options
                     // $options->$imgType = $attach_data;
                     // $options->save();
                     /** 
                      * do action to control how to store data
                      * @param $attach_data the array of image data
                      * @param $request['data']
                      * @param $attach_id the uploaded file id
                      */
                     do_action('ae_upload_image', $attach_data, $_POST['data'], $attach_id);
                     $res = array('success' => true, 'msg' => __('Branding image has been uploaded successfully', 'aecore-class-ae-page-backend'), 'data' => $attach_data);
                 } catch (Exception $e) {
                     $res['msg'] = __('Error when updating settings.', 'aecore-class-ae-page-backend');
                 }
             } else {
                 $res['msg'] = $attach_id->get_error_message();
             }
         } else {
             $res['msg'] = __('Uploaded file not found', 'aecore-class-ae-page-backend');
         }
     }
     // send json to client
     wp_send_json($res);
 }
Exemplo n.º 3
0
 /**
  * update branding : logo, mobile icon
  */
 function upload_image()
 {
     $res = array('success' => FALSE, 'msg' => __('There is an error occurred', ET_DOMAIN), 'code' => 400);
     // check fileID
     if (!isset($_POST['fileID']) || empty($_POST['fileID']) || !isset($_POST['imgType']) || empty($_POST['imgType'])) {
         $res['msg'] = __('Missing image ID', ET_DOMAIN);
     } else {
         $fileID = $_POST["fileID"];
         $imgType = $_POST['imgType'];
         // check ajax nonce
         if (!de_check_ajax_referer($imgType . '_et_uploader', FALSE, FALSE) && !check_ajax_referer($imgType . '_et_uploader', FALSE, FALSE)) {
             $res['msg'] = __('Security error!', ET_DOMAIN);
         } elseif (isset($_FILES[$fileID])) {
             // handle file upload
             $attach_id = et_process_file_upload($_FILES[$fileID], 0, 0, array('jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'bmp' => 'image/bmp', 'tif|tiff' => 'image/tiff'));
             if (!is_wp_error($attach_id)) {
                 try {
                     $attach_data = et_get_attachment_data($attach_id);
                     $options = AE_Options::get_instance();
                     // save this setting to theme options
                     // $options->$imgType = $attach_data;
                     // $options->save();
                     /**
                      * do action to control how to store data
                      *
                      * @param $attach_data the array of image data
                      * @param $request     ['data']
                      * @param $attach_id   the uploaded file id
                      */
                     do_action('ae_upload_image', $attach_data, $_POST['data'], $attach_id);
                     $res = array('success' => TRUE, 'msg' => __('Branding image has been uploaded successfully', ET_DOMAIN), 'data' => $attach_data);
                 } catch (Exception $e) {
                     $res['msg'] = __('Error when updating settings.', ET_DOMAIN);
                 }
             } else {
                 $res['msg'] = $attach_id->get_error_message();
             }
         } else {
             $res['msg'] = __('Uploaded file not found', ET_DOMAIN);
         }
     }
     // send json to client
     wp_send_json($res);
 }