How to set file type in wp_handle_upload?

Got it, looking at the source code I came up with this: wp_handle_upload($file_input, array(‘test_form’ => false, ‘mimes’ => array(‘csv’ => ‘text/csv’))); To override the mime types just pass mimes as an array wit the key being the file extension and the value as the mime type.

How can you limit the number of images / videos that can be uploaded to a WordPress post

try this: add_filter(‘wp_handle_upload_prefilter’, ‘limit_wp_handle_upload_prefilter’); function yoursite_wp_handle_upload_prefilter($file) { // This bit is for the flash uploader if ($file[‘type’]==’application/octet-stream’ && isset($file[‘tmp_name’])) { $file_size = getimagesize($file[‘tmp_name’]); if (isset($file_size[‘error’]) && $file_size[‘error’]!=0) { $file[‘error’] = “Unexpected Error: {$file_size[‘error’]}”; return $file; } else { $file[‘type’] = $file_size[‘mime’]; } } if ($post_id = (isset($_REQUEST[‘post_id’]) ? $_REQUEST[‘post_id’] : false)) { if (count(get_posts(“post_type=attachment&post_parent={$post_id}”))>3) $file[‘error’] … Read more

How can I prevent uploading bmp image?

The magic is in get_allowed_mime_types() which calls the upload_mimes filter. That is filtering a default array consisting of keys as a non-terminated regular expression of file-extensions and the mapped mime-type as values: array( ‘jpg|jpeg|jpe’ => ‘image/jpeg’, ‘gif’ => ‘image/gif’, ‘png’ => ‘image/png’, ‘bmp’ => ‘image/bmp’, ‘tif|tiff’ => ‘image/tiff’, ‘ico’ => ‘image/x-icon’, …. } so hooking … Read more

How to prevent upload of a multiple sizes of images

I believe those are probably generated by the default WordPress sizes – thumbnail, medium and large. (See Appearance > Media for where those sizes are set). If you want to eliminate the extra image sizes the simplest way might be to eliminate some of your theme’s custom image sizes and use the defaults instead. OR, … Read more

Using file_exists to check file in Uploads

You can’t use a file url in file_exists() like this: file_exists( “http://example.com/wp-content/uploads/Example_Name_2_SM.jpg” ); You should rather use an absolute file path, for example: file_exists( “/absolute/path/to/wp-content/uploads/Example_Name_2_SM.jpg” ); Then you should try $meta = get_post_meta( $post->ID, ‘_meta_example_name’, true ); $file = $upload_basedir . “https://wordpress.stackexchange.com/” . $meta . ‘_7_SM.jpg’; if ( file_exists( $file ) ) { //… } … Read more

Create Image Uploader for Widget

Let’s face it in detail: The registered sidebar (with the ID left-sidebar) has two arguments to wrap the whole widget (before_widget and after_widget) which you can output via echo $before_widget and echo $after_widget in your widget (see my version below): <?php // Register sidebar if (function_exists(‘register_sidebar’)) { register_sidebar( array( ‘name’ => ‘Left Sidebar’, ‘id’ => … Read more

Automating a Daily Picture Blog?

There are lots of ways to accomplish a daily picture blog so I’ll just give you how I’d approach it. If I wanted to set up a photoblog on WordPress I’d start with a Flickr account and leverage it (or if you don’t like Flickr for some reason you can also look at PhotoBucket, SmugMug, … Read more

How to make WordPress use protocol indepentent upload files?

You can define a function to remove the protocol and hook it to the attachment URL: function wpse_79958_remove_protocol_from_attachment($url) { $url = str_replace(array(‘http:’, ‘https:’), ”, $url); return $url; } add_filter( ‘attachment_link’, ‘wpse_79958_remove_protocol_from_attachment’ ); Also consider to use relative URLs for attachments by using WordPress builtin function wp_make_link_relative: add_filter( ‘attachment_link’, ‘wp_make_link_relative’ ); Place this code to your … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)