-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathupload.php
More file actions
33 lines (27 loc) · 880 Bytes
/
upload.php
File metadata and controls
33 lines (27 loc) · 880 Bytes
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
<?php
// If this file is called directly, abort.
if ( ! defined( 'ABSPATH' ) ) {
die('Error');
}
/**
* Process file uploads for importer
*/
function cherry_plugin_process_upload() {
// verify nonce
check_ajax_referer( 'cherry_plugin_upload', '_wpnonce' );
// check user caps
if ( !current_user_can( 'import' ) ) {
wp_die( 'You don\'t have permissions to do this', 'Error' );
}
if ( strtolower( $_SERVER['REQUEST_METHOD'] ) != 'post' ) {
wp_die( 'Wrong method', 'Error' );
}
if ( array_key_exists( 'file', $_FILES ) ) {
$upload_dir = isset($_REQUEST['dir']) ? $_REQUEST['dir'] : $upload_dir ;
$file_name = basename($_FILES['file']['name']);
$upload_file = $upload_dir . $file_name;
$result = move_uploaded_file($_FILES['file']['tmp_name'], $upload_file);
}
die();
}
add_action( 'wp_ajax_cherry_import_files', 'cherry_plugin_process_upload' );