Instead of opening up Wordpress Media Upload Window I just want to open user's file explorer on their device right away after clicking on upload and then upon selecting files in their file explorer to upload them directly without Wordpress Media Upload Window.. How can I achieve this?
-
Hi Marko I., could you provide more details on what you've tried already (and why it didn't work)?– kraftnerMar 1, 2017 at 15:34
-
I couldn't find literally any resource for this so I didn't do anything so far..– Marko I.Mar 1, 2017 at 15:36
-
you need to upload an image in the admin and on the outer part of the site?– TrubinEMar 1, 2017 at 17:09
-
on the outer part of the site.. on the frontend @TrubinE– Marko I.Mar 1, 2017 at 17:11
1 Answer
Use function wp_handle_upload()
The documentation is an example:
https://codex.wordpress.org/Function_Reference/wp_handle_upload
Example:
<form class="user_upload_photo none" enctype="multipart/form-data" action="" method="POST">
<?php wp_nonce_field('my_file_upload', 'fileup_nonce'); ?>
<input class="file_input_text" name="my_file_upload" type="file" />
<input class="btn" type="submit" value="Загрузить файл" />
</form>
handler:
if (wp_verify_nonce($_POST['fileup_nonce'], 'my_file_upload')) {
if (!function_exists('wp_handle_upload'))
require_once( ABSPATH . 'wp-admin/includes/file.php' );
$file = &$_FILES['my_file_upload'];
$overrides = array('test_form' => false);
$movefile = wp_handle_upload($file, $overrides);
if ($movefile) {
echo "File downloaded";
} else {
echo "when the file download error";
}
}