wooccm_front_endupload

The WooCommerce Checkout Manager wooccm front endupload function.

Description

wooccm_front_endupload(); 

Usage

  1. if ( !function_exists( 'wooccm_front_endupload' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-checkout-manager/includes/classes/main.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wooccm_front_endupload(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/classes/main.php  
  1. function wooccm_front_endupload() { 
  2.  
  3. require_once( ABSPATH . 'wp-admin/includes/file.php' );  
  4. require_once( ABSPATH . 'wp-admin/includes/media.php' ); 
  5.  
  6. $wp_upload_dir = wp_upload_dir(); 
  7. $name = $_REQUEST["name"]; 
  8. $upload_overrides = array( 'test_form' => false ); 
  9. $number_of_files = 0; 
  10.  
  11. $file = array( 
  12. 'name' => $_FILES[''.$name.'']['name'],  
  13. 'type' => $_FILES[''.$name.'']['type'],  
  14. 'tmp_name' => $_FILES[''.$name.'']['tmp_name'],  
  15. error => $_FILES[''.$name.''][error],  
  16. 'size' => $_FILES[''.$name.'']['size'] 
  17. ); 
  18.  
  19. $movefile = wp_handle_upload($file, $upload_overrides); 
  20.  
  21. $attachment = array( 
  22. 'guid' => $movefile['url'],  
  23. 'post_mime_type' => $movefile['type'],  
  24. 'post_title' => preg_replace( '/\.[^.]+$/', '', basename($movefile['file'])),  
  25. 'post_content' => '',  
  26. 'post_status' => 'inherit' 
  27. ); 
  28.  
  29. $attach_id = wp_insert_attachment( $attachment, $movefile['url'] ); 
  30. $number_of_files++; 
  31.  
  32. echo json_encode( array( $number_of_files, $attach_id ) ); 
  33.  
  34. die();