I want to add a media uploader to a plugin.
I have found and read This
It does shows the media uploader and it let's me select an image but as it uploads it gives me some crappy error: Error occurred during upload. Try again later.
This might be slight off because I translated it.
I don't know how to search for the real error here.
Can anyone tell me how to find it?
<?php
wp_enqueue_script('jquery');
wp_enqueue_media();
?>
<div>
<label for="image_url">Image</label>
<input type="text" name="image_url" id="image_url" class="regular-text">
<input type="button" name="upload-btn" id="upload-btn" class="button-secondary" value="Upload Image">
</div>
<script type="text/javascript">
jQuery(document).ready(function($){
$('#upload-btn').click(function(e) {
e.preventDefault();
var image = wp.media({
title: 'Upload Image',
multiple: false
}).open()
.on('select', function(e){
var uploaded_image = image.state().get('selection').first();
console.log(uploaded_image);
var image_url = uploaded_image.toJSON().url;
$('#image_url').val(image_url);
});
});
});
</script>
If it is possible I would like to add an items to the Media Uploader:
Choose a folder to upload the file to.
Not by the person who is uploading but just a folder I create before the upload
M.
---------------------------------------
UPDATE:
Weird thing happend
I have disabled the WP_DEBUG function and now everything is working. If I set it to true
there are no errors...