Articles of uploads

Rename image during upload using date and time stamp?

I am trying to rename images during upload to avoid problems with image file names containig special characters and file names with non-latin characters. I found this function to rename images in WordPress: function sanitize_file_uploads( $file ){ $file[‘name’] = sanitize_file_name($file[‘name’]); $file[‘name’] = preg_replace(“/[^a-zA-Z0-9\_\-\.]/”, “”, $file[‘name’]); $file[‘name’] = strtolower($file[‘name’]); add_filter(‘sanitize_file_name’, ‘remove_accents’); return $file; } add_filter(‘wp_handle_upload_prefilter’, ‘sanitize_file_uploads’); […]

Accessing a random image via ajax

The goal with this is to create a random banner, managed in the wp admin. I can create a banner solution in the wp admin without an issue but need a little help on the ajax side. I have an image http://example.com/wp-content/uploads/2015/12/image-name.jpg I created a random_banner function in functions.php. add_action( ‘wp_ajax_random_banner’, ‘random_banner’ ); add_action( ‘wp_ajax_nopriv_random_banner’, […]

Add item to media library from blob or dataUrl

I’m trying to build a webcam snapshot recorder. It should take a picture and upload it to the WP media library via ajax / async-upload. Already managed to add a view to the media library. Recording also works. I can either store the raw image data in blob or in base 64 encoded string (like […]

Moving Media Library

I downloaded all files from wp-content/uploads and copied to new Wordpres instance on localhost (Windows IIS Express also on MacOS with MAMP). Unfortunately in both cases I don’t see my files in Media Library. Isn’t just needed to copy and paste files to wp-content/uploads to get access to them fom new, completely clean instance of […]

How to restrict wp-admin and prevent upload errors

I need to restrict wp-admin access to all users who cant manage_options and still let users add media on the front end. function wpse_11244_restrict_admin() { if ( ! current_user_can( ‘manage_options’ ) && $_SERVER[‘PHP_SELF’] != ‘/wp-admin/admin-ajax.php’ ) { wp_redirect( home_url() ); } } add_action( ‘admin_init’, ‘wpse_11244_restrict_admin’, 1 ); I found this code on stack overflow and […]

Why images/photos after being uploaded to my wordpress site get slightly blurry?

I am trying to figure out the problem stated in the title. Every image/photo I upload to my wordpress site gets slightly blurry. I format them according to my wp theme requirements, however after the image is processed by wordpress and I open the site in a browser I is slightly blurry. This is specially […]

Get an uploaded attachments local server path?

All the wordpress functions for retrieving media details seem to give you the web url of a file uploaded. I want to the local server drive/folder path, ideally relative to the install of wordpress. I have the attachment id value to hand so can parse that to a function, if only I knew what it […]

How to upload multiple images on frontend to ACF gallery using update_field

I’m trying to save images submitted on a frontend form in a way that they are accessible via the ACF backend. In how to upload an image on ACF with update_field on wordpress, someone provided a solution for a single image upload (and consequently a single ACF image field). I thought it should be pretty […]

How to retrieve alt attribute for an attachment (uploaded image)?

I have some IDs of attachments (images, not from current post). How to I get the alt attribute for those images? I have tried to look into wp_get_attachment_image_src and wp_get_attachment_metadata but couldn’t find the alt attribute stored in neither of those this is where I’m looking for the alt: while(the_repeater_field(‘featured_pics’)): //this is an array of […]

What function can I use to override the multisite maximum file size upload restriction?

What function can I use to override the multisite maximum file size upload restriction? I have already maxed out the kb upload size and ensured that the max file upload size in php.ini is over 50mb, yet still I’m getting an error uploading an 11mb file.