Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

WordPress-Plugin: Show Upload Info

View upload-info-shortcode.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
<?php
/*
Plugin Name: Show Upload Info
Description: Insert [uploadinfo] into a page to get detailed information about your upload environment.
Version: 1.3
Author: Thomas Scholz
Author URI: http://toscho.de
License: GPL v2
*/
if ( ! function_exists( 'uploadinfo_shortcode' ) )
{
/**
* Shows detailed information about the WordPress upload directory.
*
* @return string
*/
function uploadinfo_shortcode()
{
$info = array();
$out = "<b>WP Info</b>\n";
// @see http://codex.wordpress.org/Function_Reference/wp_upload_dir
$uploads = wp_upload_dir();
$uploads['upload path exists'] = is_dir( $uploads['path'] );
$uploads['upload basedir exists'] = is_dir( $uploads['basedir'] );
if ( function_exists( 'is_multisite' ) )
{
$uploads['WP Multisite'] = is_multisite();
}
$stats = stat( $uploads['basedir'] );
if ( function_exists( 'posix_getpwuid' ) )
{
$upload_uid = posix_getpwuid( $stats['uid'] );
$upload_gid = posix_getgrgid( $stats['gid'] );
$uploads['Upload Dir Owner'] =
'ID: ' . $stats['uid'] . ', name: ' . $upload_uid['name'];
$uploads['Upload Dir Group'] =
'ID: ' . $stats['gid'] . ', name: ' . $upload_gid['name'];
}
$uploads['yearmonth_folders'] =
(bool) get_option( 'uploads_use_yearmonth_folders' );
$uploads['Upload Dir Permissions'] = fileperms( $uploads['basedir'] );
$uploads['Upload Dir Permissions'] = substr(
sprintf( '%o', fileperms( $uploads['basedir'] ) ), -4
);
$uploads['Upload Dir Writable'] =
is_writable( $uploads['basedir'] );
$uploads['Upload Path Writable'] =
is_writable( $uploads['path'] );
$uploads['upload_max_filesize'] = ini_get( 'upload_max_filesize' );
$upload_tmp_dir = ini_get( 'upload_tmp_dir' );
$uploads['upload_tmp_dir'] = $upload_tmp_dir ? $upload_tmp_dir : 'Not set';
$uploads['file_uploads'] = ini_get( 'file_uploads' ) ? 'Allowed' : 'Forbidden';
$base_dir = ini_get( 'open_basedir' );
$base_dir = explode( PATH_SEPARATOR, $base_dir );
$base_dir = implode( "\n ", $base_dir );
$uploads['open_basedir'] = $base_dir;
$uploads['Upload Rights'] = current_user_can( 'upload_files' );
foreach ( $uploads as $key => $val )
{
$val = is_bool( $val ) ? ( $val ? 'True' : 'False' ) : $val;
$out .= str_pad( ucwords( $key ) . ':', 23) . "$val\n";
}
unset( $key, $val );
$out .= "\n<b>System Info</b>\n";
$current_uid = posix_geteuid();
$current_info = posix_getpwuid( $current_uid );
$current_group = posix_getgrgid( $current_info['gid'] );
$info['PHP version'] = phpversion();
$info['Temp Dir'] = realpath( sys_get_temp_dir() );
$info['Temp Dir Owner'] = fileowner( $info['Temp Dir'] );
$info['Temp Dir Writable'] = is_writable( $info['Temp Dir'] );
$info['Current Process Owner'] =
'ID: ' . $current_uid . ', name: ' . $current_info['name'];
$info['Current Process Group'] =
'ID: ' . $current_info['gid'] . ', name: ' . $current_group['name'];
foreach ( $info as $key => $val )
{
$val = is_bool( $val ) ? ( $val ? 'True' : 'False' ) : $val;
$out .= str_pad("$key:", 23) . "$val\n";
}
return "<pre class='debug uploadinfo'>$out</pre>";
}
}
/**
* For PHP versions prior to 5.2.1.
* From the user notes to sys_get_temp_dir()
*
* @return string
*/
if ( ! function_exists( 'sys_get_temp_dir' ) )
{
function sys_get_temp_dir()
{
if ( $temp = getenv( 'TMP' ) )
return $temp;
if ( $temp = getenv( 'TEMP' ) )
return $temp;
if ( $temp = getenv( 'TMPDIR' ) )
return $temp;
$temp = tempnam( __FILE__, '' );
if ( file_exists( $temp ) )
{
unlink( $temp );
return dirname( $temp );
}
return null;
}
}
add_shortcode( 'uploadinfo', 'uploadinfo_shortcode' );

thanks for sharing! this helped me alot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.