PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
mainwp / class / class-mainwp-file-uploader-handle.php

class-mainwp-file-uploader-handle.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 6.2.2, at class/class-mainwp-file-uploader-handle.php

78 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP_File_Uploader_Handle
4 *
5 * Handle file uploads via regular form post (uses the $_FILES array)
6 *
7 * @see dropzone.js
8 *
9 * @package MainWP/Dashboard
10 */
11
12 namespace MainWP\Dashboard;
13
14 // Exit if accessed directly.
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 /**
20 * Class MainWP_File_Uploader_Handle
21 *
22 * @package MainWP\Dashboard
23 */
24 class MainWP_File_Uploader_Handle { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
25
26 /**
27 * Save the file to the specified path.
28 *
29 * @param string $path Path to save file to.
30 * @throws \MainWP_Exception Exception object.
31 *
32 * @return boolean TRUE on success|false on failure.
33 *
34 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_wp_file_system()
35 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_base_dir()
36 */
37 public function save( $path ) {
38 $moved = false;
39 $tmp_name = isset( $_FILES['qqfile']['tmp_name'] ) && MainWP_Utility::valid_file_check( $_FILES['qqfile']['tmp_name'] ) ? $_FILES['qqfile']['tmp_name'] : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- verify in caller.
40
41 //phpcs:disable WordPress.WP.AlternativeFunctions -- custom process.
42 if ( ! is_dir( dirname( $path ) ) ) {
43 mkdir( dirname( $path ), 0750, true ); // MWP-1558: tightened from 0777.
44 }
45
46 if ( empty( $_REQUEST['dzchunkbyteoffset'] ) && file_exists( $path ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- verified.
47 unlink( $path ); // first chuck, delete file if existed, to create new file.
48 }
49
50 // to append to file, wp_filesystem put_contents does not support.
51 $str = file_get_contents( $tmp_name );
52
53 $moved = file_put_contents( $path, $str, FILE_APPEND );
54
55 if ( ! file_exists( $path ) ) {
56 throw new MainWP_Exception( 'Unable to save the file to the MainWP upload directory, please check your system configuration.' );
57 }
58
59 //phpcs:enable WordPress.WP.AlternativeFunctions
60
61 if ( ! $moved ) {
62 return false;
63 }
64
65 return true;
66 }
67
68 /** Get the File Name. */
69 public function get_name() {
70 return isset( $_FILES['qqfile']['name'] ) ? $_FILES['qqfile']['name'] : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- global variable.
71 }
72
73 /** Get the File Size. */
74 public function get_size() {
75 return isset( $_FILES['qqfile']['size'] ) ? $_FILES['qqfile']['size'] : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- global variable.
76 }
77 }
78