Organize uploaded media files

Thans but I’ve found the solution, what it need to do is to edit the site (Network -> Sites -> Edit -> Settings ) and change the following parameters: Uploads Use Yearmonth Folders 0 Upload Path wp-content/blogs.dir/1/uploads Fileupload Url http://www.mydomain.com/myblog/uploads

Change upload directory on custom plugin page

After working on this for a bit and checking the GLOBALS variable for anything useful, it looks like the referring URL inside of the media modal is the same URL as my custom plugin page. Using that and splitting it up a bit I was able to confirm that I am on the approrpriate page. … Read more

how to upload image using wp_handle_upload

here’s my example of how to upload multiple images: add_action( ‘add_meta_boxes’, ‘my_test_metabox’ ); function my_test_metabox() { add_meta_box( ‘my_test_metabox’, ‘File upload’, ‘my_test_metabox_out’, ‘post’ ); } add_action(‘post_edit_form_tag’, ‘update_edit_form’ ); function update_edit_form() { echo ‘ enctype=”multipart/form-data”‘; } function my_test_metabox_out( $post ) { $files = get_post_meta( $post->ID, ‘my_files’, true ); if( ! empty( $files ) ) { echo ‘Files … Read more

admin-ajax.php returns 0. How do I debug it and fix it?

Enable Debugging WordPress has constants defined in wp-config.php where you can print errors to the screen and log them in a separate file located /wp-content/debug.log. It looks like this: define( ‘WP_DEBUG’, true ); define( ‘WP_DEBUG_DISPLAY’, true ); define( ‘WP_DEBUG_LOG’, true ); You can then print your own information to the debug log at specific point … Read more

How to Reduce the Maximum Upload File Size?

You can forbid uploads of a specific size (or for other reasons) in the wp_handle_upload_prefilter hook that is used in the wp_handle_upload() function. It get’s the file array passed, it’s a single item in the PHP standard superglobal $_FILES one that is documented in the PHP Manual: POST method uploads. Just create a function and … Read more

Multisite, upload images directly to Amazon S3

If you are running on a dedicated linux server and are comfortable with the command line, you could install s3fs. This is a program that allows you to actually mount your Amazon s3 Bucket as a directory on you server. In the standard multisite environment, media uploads for all sites but the main site are … Read more

How to register images uploaded via FTP in media library?

It’s because you’re not registering them as a media type. Every upload is a WordPress post of the attachment type. To start, it would be something like this: $file_name=”Some Name”; $file_path=”/path/to/uploads/2012/08/04/newfile.jpg”; $file_url=”http://url/to/uploads/2012/08/04/newfile.jpg”; $wp_filetype = wp_check_filetype($file, null); $attachment = array( ‘guid’ => $file_url, ‘post_mime_type’ => $wp_filetype[‘type’], ‘post_title’ => $file_name, ‘post_status’ => ‘inherit’, ‘post_date’ => date(‘Y-m-d H:i:s’) … Read more