-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·134 lines (114 loc) · 4.8 KB
/
index.php
File metadata and controls
executable file
·134 lines (114 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/*
* Plugin Name: Secure PDF Uploader
* Plugin URL: http://digitaldesigneronline.com/members/plugins/secure-pdf-uploader/
* Description: Provides a easy upload interface for the PDF Watermarker plugin.
* Version: 1.0
* Author: Chad Warford - Fullstack Developer
* Author URI: http://onlinelifesaver.com
*/
// Begin Registering Admin Menu Items
add_action( 'admin_menu', 'pdf_upload_admin_menu' );
function pdf_upload_admin_menu() {
add_menu_page( 'Secure PDFs', 'Secure PDF', 'manage_options', 'PDF-Uploader/pdfupload.php', 'pdfupload_admin_page', 'dashicons-media-text', 80 );
}
// End Adding Admin Menu Items
// Begin Adding Support Page Content
function pdfupload_admin_page(){
?>
<style>
<?php include '../wp-content/plugins/PDF-Uploader/support-files/stylesheet.css'; ?>
</style>
<div class="wrap">
<div id="contact">
<div style="text-align:center;">
<img src="http://digitaldesigneronline.com/wp-content/uploads/2017/06/ddo-logo-3d.png" alt="logo" style="display:block;margin:auto;text-align:center;">
<h1>Secure PDF File Upload</h1>
<p>Adding a watermark to your PDF files is as easy as uploading the file using the form below.<br>
Upon successful submission of your PDF file you will receive the uploaded PDF files URL which you can then use when linking to the PDF within any page or post you desire.</p>
<p>The PDF file when linked to using the URL provided will automatically acquire a watermark when loaded within the browser of the specific logged in user as well as the current date and time.</p>
<form action="" method="post" enctype="multipart/form-data">
<h3>Select image to upload:</h3><br>
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload PDF File" name="submitUpload">
</form>
<?php
$target_dir = "../wp-content/plugins/chadpdf/engine/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if(isset($_POST["submitUpload"])) {
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "pdf") {
echo "Sorry, only PDF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "File uploaded successfully use the following URL when linking to your PDF <br> https://digitaldesigneronline.com/wp-content/plugins/chadpdf/engine/simple1.php?filename=" . basename( $_FILES["fileToUpload"]["name"]). "";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}
// Check if file already exists
/**
* FILE DELETION HANDLER
* I moved it here as it needs to be above the form
*/
function delete_file($file) {
if(!unlink( get_home_path() . $file )) {
echo "Sorry! your file cannot be deleted. Please try again later";
}
else {
echo "File deleted successfully!";
}
}
if(isset($_POST['submit'])){
if(!empty($_POST['file'])) { // check if the checkbox was checked.
foreach($_POST['file'] as $file) {
// call delete function here.
delete_file($file);
}
}
else{
echo "No file selected. you must select at one file to delete.";
}
}
?>
</div>
<?php
if ($handle = opendir('../wp-content/plugins/chadpdf/engine/')) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." && strtolower(substr($file, strrpos($file, '.') + 1)) == 'pdf')
{
$thelist .= '<tr><td><input type="checkbox" name="file[]" value="/wp-content/plugins/chadpdf/engine/'.$file.'"></td><td><a href="http://digitaldesigneronline.com/wp-content/plugins/chadpdf/engine/simple1.php?filename='.$file.'" target="_blank" style="font-size:18px;">'.$file.'</a></td></tr>';
}
}
closedir($handle);
}
?>
<form id="deletionForm" method="post" action="">
<table>
<?=$thelist?>
</table>
<input type="submit" name="submit" value="Delete Selection">
</form>
</div>
<?php
}
// End Adding Secure PDF Upload Page Content