PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.2
V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 2.10.2 All 137 releases
bit-form / includes / Core / Util / FileHandler.php

FileHandler.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 1.2, at includes/Core/Util/FileHandler.php

95 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace BitCode\BitForm\Core\Util;
3
4 final class FileHandler
5 {
6 public function rmrf($dir)
7 {
8 if (is_dir($dir)) {
9 $objects = scandir($dir);
10 foreach ($objects as $object) {
11 if ($object != "." && $object != "..") {
12 if (is_dir($dir. DIRECTORY_SEPARATOR .$object) && !is_link($dir.DIRECTORY_SEPARATOR.$object)) {
13 $this->rmrf($dir. DIRECTORY_SEPARATOR .$object);
14 } else {
15 unlink($dir. DIRECTORY_SEPARATOR .$object);
16 }
17 }
18 }
19 rmdir($dir);
20 } else {
21 unlink($dir);
22 }
23 }
24
25 public function cpyr($source, $destination)
26 {
27 if (is_dir($source)) {
28 mkdir($destination);
29 // chmod($destination, 0744);
30 $objects = scandir($source);
31 foreach ($objects as $object) {
32 if ($object != "." && $object != "..") {
33 if (is_dir($source. DIRECTORY_SEPARATOR .$object) && !is_link($source.DIRECTORY_SEPARATOR.$object)) {
34 cpyr($source. DIRECTORY_SEPARATOR .$object, $destination. DIRECTORY_SEPARATOR .$object);
35 } elseif (is_file($source. DIRECTORY_SEPARATOR .$object)) {
36 copy($source. DIRECTORY_SEPARATOR .$object, $destination. DIRECTORY_SEPARATOR .$object);
37 // chmod($destination. DIRECTORY_SEPARATOR .$object, 0644);
38 } else {
39 symlink($source. DIRECTORY_SEPARATOR .$object, $destination. DIRECTORY_SEPARATOR .$object);
40 }
41 }
42 }
43 } else {
44 copy($source, $destination);
45 }
46 }
47
48 public function moveUploadedFiles($file_details, $form_id, $entry_id)
49 {
50 $file_upoalded = array();
51 $_upload_dir = BITFORMS_UPLOAD_DIR.DIRECTORY_SEPARATOR.$form_id.DIRECTORY_SEPARATOR.$entry_id;
52 wp_mkdir_p($_upload_dir);
53 if (is_array($file_details['name'])) {
54 foreach ($file_details['name'] as $key => $value) {
55 //check accepted filetype in_array($file_details['name'][$key], $supported_files) else \
56 if (!empty($value)) {
57 $fileNameCount = 1;
58 // $file_upoalded[$key] = time()."_$value";
59 $file_upoalded[$key] = sanitize_file_name($value);
60 while (file_exists($_upload_dir.DIRECTORY_SEPARATOR.$file_upoalded[$key])) {
61 $file_upoalded[$key] = sanitize_file_name(preg_replace("/(.[a-z A-Z 0-9]+)$/", "__{$fileNameCount}$1", $value));
62 $fileNameCount = $fileNameCount + 1;
63 if ($fileNameCount === 11) {
64 break;
65 }
66 }
67 \move_uploaded_file($file_details['tmp_name'][$key], $_upload_dir.DIRECTORY_SEPARATOR.$file_upoalded[$key]);
68 }
69 }
70 } else {
71 if (!empty($file_details['name'])) {
72 $fileNameCount = 1;
73 $file_upoalded[0] = sanitize_file_name($file_details['name']);
74 while (file_exists($_upload_dir.DIRECTORY_SEPARATOR.$file_upoalded[0])) {
75 $file_upoalded[0] = sanitize_file_name(preg_replace("/(.[a-z A-Z 0-9]+)$/", "__{$fileNameCount}$1", $file_details['name']));
76 $fileNameCount = $fileNameCount + 1;
77 if ($fileNameCount === 11) {
78 break;
79 }
80 }
81 \move_uploaded_file($file_details['tmp_name'], $_upload_dir.DIRECTORY_SEPARATOR.$file_upoalded[0]);
82 }
83 }
84 return $file_upoalded;
85 }
86
87 public function deleteFiles($form_id, $entry_id, $files)
88 {
89 $_upload_dir = BITFORMS_UPLOAD_DIR.DIRECTORY_SEPARATOR.$form_id.DIRECTORY_SEPARATOR.$entry_id;
90 foreach ($files as $name) {
91 unlink($_upload_dir.DIRECTORY_SEPARATOR.$name);
92 }
93 }
94 }
95