forked from hunk/Magic-Fields
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RCCWP_upload.php
executable file
·266 lines (204 loc) · 8.03 KB
/
RCCWP_upload.php
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php
// use wp-load. Normally right here, but if it's not...
if( file_exists('../../../wp-load.php') )
{
require_once('../../../wp-load.php');
$loaded = true;
} // ...then look over here
elseif( file_exists('./mf-config.php') )
{
include_once('./mf-config.php');
require_once(MF_WP_LOAD);
$loaded = true;
}
if( $loaded !== true ){
die('Could not load wp-load.php, edit/add mf-config.php and define MF_WP_LOAD to point to a valid wp-load file.');
}
global $mf_domain, $wpdb;
if( !( is_user_logged_in() && current_user_can('upload_files') ) )
die(__("You don't have permission to upload files, contact to the administrator for more information!",$mf_domain));
?>
<html>
<head>
<?php
//Change the nameinput magicfields[type][id gruop index][id field index] => magicfields_{type}_{id group index}_{if field index}
function changeNameInput($inputName){
$inputName = filter_var($inputName, FILTER_SANITIZE_SPECIAL_CHARS);
$patterns = array('/\[/','/\]/');
$replacements = array('_','');
return preg_replace($patterns,$replacements,$inputName);
}
if (isset($_POST['fileframe'])){
if ( empty($_POST) || !wp_verify_nonce($_POST['checking'],'nonce_upload_file') ){
print 'Sorry, your nonce did not verify.';
exit;
}
$operationSuccess = "false";
//type of upload
if(!empty($_POST['type'])){
if ($_POST['type'] == '1'){
$acceptedExts = "image";
}elseif ($_POST['type'] == '2'){
$acceptedExts = "audio";
}
}else{
$acceptedExts = "file";
}
// A file is uploaded
if (isset($_FILES['file']) && (!empty($_FILES['file']['tmp_name']))) // file was send from browser
{
if ($_FILES['file']['error'] == UPLOAD_ERR_OK) { //no error
$special_chars = array (' ','`','"','\'','\\','/'," ","#","$","%","^","&","*","!","~","‘","\"","’","'","=","?","/","[","]","(",")","|","<",">",";","\\",",","+","-");
$filename = str_replace($special_chars,'',$_FILES['file']['name']);
$filename = time() . $filename;
$action_mf_file = $_FILES['file'];
@move_uploaded_file( $_FILES['file']['tmp_name'], MF_FILES_PATH . $filename );
@chmod(MF_FILES_PATH . $filename, 0644);
$result_msg = '<span class="mf-upload-success">'.__("Successful upload",$mf_domain).'!</span>' ;
//Checking the mimetype of the file
if(valid_mime($_FILES['file']['type'],$acceptedExts)){
$operationSuccess = "true";
$action_mf_file['tmp_name'] = MF_FILES_PATH . $filename;
do_action( 'mf_after_upload_file', $action_mf_file );
}else{
$operationSuccess = "false";
//deleting unaccepted file
$file_delete = MF_FILES_PATH.$filename;
unlink($file_delete);
}
}elseif ($_FILES['file']['error'] == UPLOAD_ERR_INI_SIZE){
$result_msg = '<span class="mf-upload-error">'.__('The uploaded file exceeds the maximum upload limit',$mf_domain).'!</span>';
}else{
$result_msg = '<span class="mf-upload-error">'.__("Upload Unsuccessful",$mf_domain).'!</span>';
}
}
// If operation is success, make sure the file was created properly
if ($operationSuccess == "true"){
if ($fp_check_file = @fopen(MF_FILES_PATH . $filename, 'rb')) {
fclose($fp_check_file);
}else{
$operationSuccess = "false";
$result_msg = __("Failed to upload the file!",$mf_domain);
}
}else{
$result_msg = '<span class="mf-upload-error">'.__("Upload Unsuccessful!",$mf_domain).'</span>';
}
?>
<script type="text/javascript" charset="utf-8">
<?php
$idField = changeNameInput($_POST['input_name']);
?>
// The code that runs after the file is uploaded
var par = window.parent.document;
var iframe = par.getElementById('upload_internal_iframe_<?php echo $idField;?>');
par.getElementById('upload_progress_<?php echo $idField;?>').innerHTML = '<?php echo $result_msg?>';
<?php
// update url, only for file
$str = '<span id="actions-'.$idField.'"><a href="'.MF_FILES_URI.$filename.'" target="_blank" class="mf-file-view">'.__("View Current",$mf_domain).'</a></span>';
$str .='<a href="javascript:void(0);" id="remove-'.$idField.'" class="mf-file-delete">'.__("Delete",$mf_domain).'</a>';
?>
par.getElementById('photo_edit_link_<?php echo $idField;?>').innerHTML = '<?php echo $str?>';
iframe.style.display="";
if ( "<?php echo $operationSuccess;?>" == "true"){
old_file = par.getElementById("<?php echo $idField; ?>").value;
if(old_file != '' ){
delete_field = par.getElementById("magicfields_remove_files").value;
if(delete_field != ''){
par.getElementById("magicfields_remove_files").value = delete_field+"|||"+old_file;
}else{
par.getElementById("magicfields_remove_files").value = old_file;
}
}
par.getElementById("<?php echo $idField; ?>").value = "<?php echo $filename?>";
//Set image
<?php
//$newImagePath = PHPTHUMB.'?&w=150&h=120&src='.MF_FILES_URI.$filename;
if($acceptedExts == "image") {
$newImagePath = aux_image($filename,'w=150&h=120&zc=1');
}else{
$newImagePath = "";
}
if (isset($_POST['imageThumbID'])){ ?>
if( par.getElementById('<?php echo filter_var($_POST['imageThumbID'], FILTER_SANITIZE_SPECIAL_CHARS); ?>') ) {
par.getElementById('<?php echo filter_var($_POST['imageThumbID'], FILTER_SANITIZE_SPECIAL_CHARS); ?>').src = "<?php echo $newImagePath;?>";
var b = " <strong><a href='#remove' class='remove' id='remove-<?php echo $idField;?>'>Delete</a></strong>";
par.getElementById("photo_edit_link_<?php echo $idField; ?>").innerHTML = b ;
}
<?php
} ?>
}
</script>
<?php
}
?>
<script language="javascript">
function upload(){
// hide old iframe
var par = window.parent.document;
<?php
$idField = changeNameInput($_GET['input_name']);
?>
var iframe = par.getElementById('upload_internal_iframe_<?php echo $idField?>');
iframe.style.display="none";
// update progress
par.getElementById('upload_progress_<?php echo $idField;?>').style.display = "block";
par.getElementById('upload_progress_<?php echo $idField;?>').innerHTML = "Transferring ";
// setTimeout("transferring(0)",1000);
// send
document.iform.submit();
}
</script>
<style>
body {
padding: 0px;
margin: 0px;
vertical-align:top;
}
</style>
<link rel='stylesheet' href='<?php echo get_bloginfo('wpurl');?>/wp-admin/css/dashboard.css' type='text/css' />
<link rel='stylesheet' href='<?php echo get_bloginfo('wpurl');?>/wp-admin/css/wp-admin.css' type='text/css' />
<link rel='stylesheet' href='<?php echo get_bloginfo('wpurl');?>/wp-admin/css/common.css' type='text/css' />
<style>
body {
background: transparent;
}
input.mf-file {
background: #f8f8f8;
}
label.label-file {
font-size: 12px;
padding-left: 2px;
}
</style>
</head>
<body>
<form name="iform" action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="fileframe" value="true" />
<?php
if (isset($_GET['imageThumbID'])) {
$imageThumbID = filter_var($_GET['imageThumbID'], FILTER_SANITIZE_SPECIAL_CHARS);
echo '<input type="hidden" name="imageThumbID" value="'.$imageThumbID.'" />';
}
if (isset($_GET['inputSize'])){
$inputSize = filter_var($_GET['inputSize'], FILTER_SANITIZE_SPECIAL_CHARS);
}
?>
<table border="0">
<tr>
<?php if($_GET['canvas']!=0){ ?>
<td width=17%><label for="file" class="label-file"><?php _e('File', $mf_domain); ?>:</label><br />
<input id="file" type="file" name="file" onchange="upload()" size="<?php echo $inputSize; ?>" class="mf-file" /></td>
<?php }else{ ?>
<td width=17%><label for="file" class="label-file"><?php _e('File', $mf_domain); ?>:</label></td>
<td><input id="file" type="file" name="file" onchange="upload()" class="mf-file" /></td>
<?php } ?>
</tr>
</table>
<?php wp_nonce_field('nonce_upload_file','checking'); ?>
<input type="hidden" name="fileframe" value="true" />
<input type="hidden" name="imgnum" />
<input type="hidden" name="input_name" value="<?php echo filter_var($_GET["input_name"], FILTER_SANITIZE_SPECIAL_CHARS); ?>" />
<input type="hidden" name="type" value="<?php echo filter_var($_GET["type"], FILTER_SANITIZE_SPECIAL_CHARS); ?>" />
</form>
</body>
</html>