Advertisement
Guest User

Supportcandy

a guest
Dec 12th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. <?php
  2. // Exit if accessed directly
  3. if ( ! defined( 'ABSPATH' ) ) exit;
  4.  
  5. $extensions = array('jpg','JPG','jpeg','JPEG','png','PNG','gif','GIF');
  6. $tempExtension = explode('.', $_FILES['file']['name']);
  7. $tempExtension = strtolower($tempExtension[count($tempExtension)-1]);
  8.  
  9. $wpsc_allow_attachment_type = get_option('wpsc_allow_attachment_type');
  10. $wpsc_attachment_type = explode(',',$wpsc_allow_attachment_type);
  11. $wpsc_attachment_type = array_map('trim', $wpsc_attachment_type);
  12. $wpsc_attachment_type = array_map('strtolower', $wpsc_attachment_type);
  13.  
  14. $file_url = '';
  15. if (in_array($tempExtension,$extensions) && in_array($tempExtension,$wpsc_attachment_type)) {
  16. $upload_dir = wp_upload_dir();
  17. $save_file_name = $_FILES['file']['name'];
  18. $save_file_name = str_replace(' ','_',$save_file_name);
  19. $save_file_name = str_replace(',','_',$save_file_name);
  20. $save_file_name = time().'_'. $save_file_name;
  21.  
  22. $save_directory = $upload_dir['basedir'] . '/wpsc/'.$save_file_name;
  23. $file_url = $upload_dir['baseurl'] . '/wpsc/'.$save_file_name;
  24. move_uploaded_file( $_FILES['file']['tmp_name'], $save_directory );
  25. }
  26. echo json_encode($file_url);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement