PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.49
E2Pdf – Export Pdf Tool for WordPress v1.32.49
1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 1.08.00 1.08.06 All 72 releases
e2pdf / classes / helper / e2pdf-files.php

e2pdf-files.php in E2Pdf – Export Pdf Tool for WordPress 1.32.49, at classes/helper/e2pdf-files.php

94 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * E2pdf Files Helper
5 *
6 * @copyright Copyright 2017 https://e2pdf.com
7 * @license GPLv3
8 * @version 1
9 * @link https://e2pdf.com
10 * @since 0.00.01
11 */
12 if (!defined('ABSPATH')) {
13 die('Access denied.');
14 }
15
16 class Helper_E2pdf_Files {
17
18 private $files = array();
19 private $helper;
20
21 // construct
22 public function __construct() {
23 $this->helper = Helper_E2pdf_Helper::instance();
24 $this->files = $_FILES;
25 }
26
27 // get
28 public function get($key) {
29
30 if (!$key) {
31 if (!empty($this->files)) {
32 return $this->files;
33 } else {
34 return false;
35 }
36 } else {
37
38 if (isset($this->files[$key])) {
39 return $this->files[$key];
40 } else {
41 return null;
42 }
43 }
44 }
45
46 // get upload max filesize
47 public function get_upload_max_filesize() {
48 $max_size = -1;
49 if ($max_size < 0) {
50 $post_max_size = $this->helper->load('convert')->to_bytes(ini_get('post_max_size'));
51 if ($post_max_size > 0) {
52 $max_size = $post_max_size;
53 }
54
55 $upload_max = $this->helper->load('convert')->to_bytes(ini_get('upload_max_filesize'));
56 if ($upload_max > 0 && $upload_max < $max_size) {
57 $max_size = $upload_max;
58 }
59 }
60 return $this->helper->load('convert')->from_bytes($max_size);
61 }
62
63 // upload
64 public function upload($file, $exts = [], $mimes = []) {
65 $upload = [
66 'name' => $file['name'],
67 'tmp_name' => $file['tmp_name'],
68 'type' => $file['type'],
69 'ext' => strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)),
70 ];
71 if (empty($file['tmp_name']) || !is_uploaded_file($file['tmp_name'])) {
72 $upload['error'] = __('Choose file to upload', 'e2pdf');
73 } elseif (!empty($file['error'])) {
74 $upload['error'] = $file['error'];
75 } elseif (!is_readable($file['tmp_name'])) {
76 $upload['error'] = __('TMP file is not readable', 'e2pdf');
77 } elseif (!empty($exts) && !in_array($upload['ext'], $exts)) {
78 $upload['error'] = sprintf(__('Only %s files allowed', 'e2pdf'), '.' . implode(', .', $exts));
79 } elseif (!empty($mimes) && function_exists('finfo_open') && function_exists('finfo_file') && defined('FILEINFO_MIME_TYPE')) {
80 $finfo = finfo_open(FILEINFO_MIME_TYPE);
81 if ($finfo !== false) {
82 $mime = @finfo_file($finfo, $file['tmp_name']);
83 finfo_close($finfo);
84 if ($mime && !in_array($mime, $mimes)) {
85 $upload['error'] = __('Invalid Type', 'e2pdf');
86 }
87 }
88 } elseif (!empty($mimes) && !in_array($upload['type'], $mimes)) {
89 $upload['error'] = __('Invalid Type', 'e2pdf');
90 }
91 return $upload;
92 }
93 }
94