I couldn’t find what was wrong with the code, so I used a different code which I found on the internet and now the window is opening.
var file_frame;
$('#csv_file_button').on('click', function(event){
event.preventDefault();
if ( file_frame ) {
file_frame.open();
return;
}
// Create the media frame.
file_frame = wp.media.frames.file_frame = wp.media({
title: $( this ).data( 'File upload' ),
button: {
text: $( this ).data( 'Upload' ),
},
multiple: false // Set to true to allow multiple files to be selected
});
// When an image is selected, run a callback.
file_frame.on( 'select', function() {
// We set multiple to false so only get one image from the uploader
attachment = file_frame.state().get('selection').first().toJSON();
$('#csv_file').attr('value',attachment.url);
});
// Finally, open the modal
file_frame.open();
});
Related Posts:
- Extend Media Library
- How to make “Upload files”selected by default in Insert Media?
- How to show all available images in WP’s media library when using the Polylang plugin?
- Saving Media – Which Hook is Fired?
- Set limit to media upload?
- WordPress 3.5: Switch back to Old Media Uploader?
- Use a separate custom table (not posts) to handle file upload data
- Insert images to post not working
- wp_generate_attachment_metadata returns empty array
- How to call WP3.5 Media Library manager?
- Settings in ‘Media > Settings’ is ignored when inserting images
- Set a maximum upload count for users on a specific user role
- How to get all files inserted (but not attached) to a post
- Password protect some uploaded files, so only logged-in users can view them
- How to protect uploads in multisite if user is not logged in?
- using media uploader to select image of specific size, enforce cropper
- Trigger JS when featured image upload window is opened in admin
- Append button to WordPress Image Details modal
- Modify the array of selected images in media modal
- 3.5 media manager add CSS / JS to new ‘tab’ iframe content
- Media uploader not work properly [closed]
- http error when uploading media files
- Retrieving JSON data in ajax request from media uploader
- How to disable WordPress Media resize different size version?
- How to change “Publish” button text for specific page
- Saving WordPress generated thumbnails in a subdirectory
- Whole bunch of errors on WP website – media upload, edit slugs, edit screen not working [closed]
- How to side load an image from a service
- Add select field to media uploader that adds a class to the image
- How to host different file formats/types for a media attachment without creating multiple attachments?
- Retroactively place uploaded media into -month, -year based folders?
- How To install AWS SDK for PHP in wordpress?
- wp.media add context
- Add fields to the WordPress media uploader
- Change default from “Attachment post URL” to “File URL” in Add Media
- Insert Image automatically when upload finishes wordpress media uploader
- How do I modify the url of uploaded media content?
- Why would media_sideload_image() not work locally?
- WordPress bug with capabilities?
- Restrict WordPress Media Library for a specific user role (users can only see/select own media)
- Media upload on WordPress changes title of image
- media_handle_upload() progress bar
- move_uploaded_file() not working on wordpress front end
- ‘An error occurred in the upload. Please try again later.’ for users with different roles
- Convert (-) and (escape) signs to (_) when uploading files on wordpress media library automatically
- wrong media url in wordpress
- Move files from flat upload directory to organised by year / month
- Can’t manipulate media uploads
- Prevent small image sizes from being uploaded
- Protecting uploads not working
- How to get the return value of wp.media({ frame: ‘post’ }) in all cases?
- Custom media uploader not showing library
- What is the way to add additional fields to attachments in 3.5+?
- Create featured image from a remote url when creating a post
- File names are being overridden when uploading new media
- upload_max_filesize is set to 64 MB already but WordPress is still showing 2 MB
- In the media Rest API, what is “missing_image_sizes”?
- Error: The uploaded file exceeds the upload_max_filesize directive in php.ini [duplicate]
- PHP error when trying to upload .mp3 files via Media Library [closed]
- How to fix the orientation of images when uploading via the WordPress Media Uploader? [closed]
- Migrating media files (documents only) to a fresh install and maintaining the same directory structure
- Flat media folder vs multiple directories
- WordPress media upload issue could not insert attachment into the database
- Thumbnail images missing in WP media library
- wp_enqueue_media() and upload_mimes problem
- Reattach media after moving to another server
- Remove Media File Items From Server That Do Not Exist in Media Library
- Better solution for managing media attachments with `wp_editor()`?
- Cropping thumbnails to specific dimensions on front end post
- What if I have a large file on the server that I want the wp library to have?
- Bug: Deleting file, then uploading same file again places file in an old month folder
- Efficient way to move media folder to another folder
- Do custom post type (CPT) attachments/media store the parent post ID?
- Create multiple folders in upload media folder
- Make inline uploader (plupload) on options page upload to a specific folder
- How to change Route respond To A specific Path?
- WordPress media has all disappeared on wp-admin but still on the server
- media file uploading
- Media Library: Remove replace images of selected author
- How to upload multiple images using WP rest API to media?
- Media files not loading
- Moving wp-content folder to public_html
- How use custom upload directories in filesystem and url based on media type or category
- media_handle_upload on mix form fields (not required file input)
- Don’t show avatars in media library
- Organizing the Media Library for Cleanup
- get users nickname uploaded media
- Drag and Drop Media Not Working in Windows 10 Edge Browser
- Insert media while posting is not working with new wordpress update
- Force relative path in media library for LAN deployment
- Make custom thumbnail size image in media_sideload_image function
- Upload more than one media files with a post
- Set featured link not showing
- wordpress 3.6 media manager cropping timestamp
- Single file upload
- Can’t upload files 1MB+ [closed]
- I am facing problem in loading and downloading Mp3 files
- How to disable direct media file access in nginx or ubuntu for non loggedin users?
- Updating Media Library PDF’s in bulk
- Does WordPress import export tool keeps the file hosted on the old website?