Changeset 3788934
- Timestamp:
- 11/07/2026 02:13:32 AM (less than one hour ago)
- Location:
- drag-and-drop-file-upload-for-elementor-forms
- Files:
-
- 21 added
- 3 edited
-
tags/1.6.3 (added)
-
tags/1.6.3/assets (added)
-
tags/1.6.3/assets/css (added)
-
tags/1.6.3/assets/css/drap_drop_file_upload.css (added)
-
tags/1.6.3/assets/images (added)
-
tags/1.6.3/assets/images/generic.png (added)
-
tags/1.6.3/assets/images/remove.png (added)
-
tags/1.6.3/assets/images/trash.png (added)
-
tags/1.6.3/assets/js (added)
-
tags/1.6.3/assets/js/admin-upload.js (added)
-
tags/1.6.3/assets/js/drap_drop_file_upload.js (added)
-
tags/1.6.3/drag-and-drop-file-upload-for-elementor-forms.php (added)
-
tags/1.6.3/fields (added)
-
tags/1.6.3/fields/dropbox.php (added)
-
tags/1.6.3/fields/file_upload.php (added)
-
tags/1.6.3/languages (added)
-
tags/1.6.3/readme.txt (added)
-
tags/1.6.3/yeekit (added)
-
tags/1.6.3/yeekit/document.php (added)
-
tags/1.6.3/yeekit/yeekit.css (added)
-
tags/1.6.3/yeekit/yeekit.js (added)
-
trunk/drag-and-drop-file-upload-for-elementor-forms.php (modified) (1 diff)
-
trunk/fields/file_upload.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
drag-and-drop-file-upload-for-elementor-forms/trunk/drag-and-drop-file-upload-for-elementor-forms.php
r3691226 r3788934 7 7 * Author: add-ons.org 8 8 * Author URI: https://add-ons.org/ 9 * Version: 1.6. 29 * Version: 1.6.3 10 10 * Requires PHP: 5.2 11 11 * Elementor tested up to: 4.2 -
drag-and-drop-file-upload-for-elementor-forms/trunk/fields/file_upload.php
r3691226 r3788934 723 723 } 724 724 if ($field["raw_value"] != "") { 725 $temp_dir = $this->get_temp_dir();726 $dir_upload = $this->get_ensure_upload_dir();725 $temp_dir = trailingslashit($this->get_temp_dir()); 726 $dir_upload = trailingslashit($this->get_ensure_upload_dir()); 727 727 $files = explode("|", $field["raw_value"]); 728 728 $new_files = array(); 729 729 $index = 0; 730 global $wp_filesystem; 731 if (empty($wp_filesystem)) { 732 require_once ABSPATH . 'wp-admin/includes/file.php'; 733 WP_Filesystem(); 734 } 730 735 foreach ($files as $file) { 731 $file_datas = explode("/", $file); 732 $filename = end($file_datas); 736 // Only accept a plain file name that was really uploaded to the temp folder 737 $filename = $this->sanitize_submitted_filename($file); 738 if ($filename === '') { 739 continue; 740 } 733 741 $temp_path = $temp_dir . $filename; 734 742 $dest_path = $dir_upload . $filename; 735 736 // Move file from temp to final uploads folder if it exists in temp737 global $wp_filesystem;738 if (empty($wp_filesystem)) {739 require_once ABSPATH . 'wp-admin/includes/file.php';740 WP_Filesystem();741 } 742 if ( $wp_filesystem->exists($temp_path)) {743 $wp_filesystem->move($temp_path, $dest_path, true);743 if (!is_file($temp_path) || !$this->is_path_inside_dir($temp_path, $temp_dir)) { 744 continue; 745 } 746 // Never overwrite a file that is already in the uploads folder 747 if (file_exists($dest_path)) { 748 continue; 749 } 750 if (!$wp_filesystem->move($temp_path, $dest_path, false) || !$this->is_path_inside_dir($dest_path, $dir_upload)) { 751 continue; 744 752 } 745 753 … … 773 781 } 774 782 783 if (empty($new_files) && !empty($field['required'])) { 784 $ajax_handler->add_error($id, esc_html__('Please upload the file again.', 'drag-and-drop-file-upload-for-elementor-forms')); 785 return; 786 } 775 787 // Update the field value in the record to use the permanent URLs 776 788 $new_raw_value = implode("|", $new_files); … … 835 847 { 836 848 $attachments_mode_attach = $this->get_file_by_attachment_type_ok($settings['form_fields'], $record, "yes"); 849 $upload_dir = $this->get_upload_dir(); 837 850 foreach ($attachments_mode_attach as $file) { 838 @wp_delete_file($file); 839 } 851 if (!is_string($file) || $this->is_protected_filename(basename($file))) { 852 continue; 853 } 854 if (is_file($file) && $this->is_path_inside_dir($file, $upload_dir)) { 855 @wp_delete_file(realpath($file)); 856 } 857 } 858 } 859 /** 860 * Turns a submitted field token (temp URL or file name) into a safe plain file name. 861 * Returns '' when the token cannot be a file uploaded by this field. 862 */ 863 private function sanitize_submitted_filename($value) 864 { 865 $value = trim(rawurldecode((string) $value)); 866 if ($value === '') { 867 return ''; 868 } 869 // Handle both separators so Windows paths cannot traverse directories 870 $value = str_replace('\\', '/', $value); 871 $value = strtok($value, '?#'); 872 $filename = sanitize_file_name(wp_basename((string) $value)); 873 if ($filename === '' || $filename[0] === '.' || $this->is_protected_filename($filename)) { 874 return ''; 875 } 876 return $filename; 877 } 878 private function is_protected_filename($filename) 879 { 880 $protected_files = array('.htaccess', 'index.php', 'index.html', 'php.ini', '.user.ini', 'web.config'); 881 return in_array(strtolower((string) $filename), $protected_files, true); 882 } 883 /** 884 * True when $path resolves to a location inside $dir. 885 */ 886 private function is_path_inside_dir($path, $dir) 887 { 888 $real_path = realpath($path); 889 $real_dir = realpath($dir); 890 if ($real_path === false || $real_dir === false) { 891 return false; 892 } 893 return strpos($real_path, trailingslashit($real_dir)) === 0; 840 894 } 841 895 private function get_file_by_attachment_type_ok($form_fields, $record, $type) -
drag-and-drop-file-upload-for-elementor-forms/trunk/readme.txt
r3691226 r3788934 2 2 Contributors: addonsorg 3 3 Tags: Elementor Forms, File field, Elementor Forms upload, uploads, uploads field 4 Stable tag: 1.6. 24 Stable tag: 1.6.3 5 5 Tested up to: 7.1 6 6 Requires PHP: 5.2 … … 60 60 61 61 == Changelog == 62 = 1.6.3 = 63 - Security: Form submissions now only accept files that were really uploaded through the field. Submitted file names are sanitized and confined to the upload folder, existing files are never overwritten, and the "files are not saved on the server" cleanup can only delete files inside the upload folder. 64 62 65 = 1.6.0 = 63 66 - Fixed: Create a temporary upload directory and automatically delete its contents daily to prevent unnecessary files from accumulating on the server.
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)