1

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?

4
  • Hi Marko I., could you provide more details on what you've tried already (and why it didn't work)?
    – kraftner
    Mar 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?
    – TrubinE
    Mar 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 1

0

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";
}
}
2
  • where should I add this handler?
    – Marko I.
    Mar 1, 2017 at 17:32
  • handler - functions.php html - to the desired page
    – TrubinE
    Mar 1, 2017 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.