Created
November 16, 2010 11:24
-
-
Save thefuxia/701718 to your computer and use it in GitHub Desktop.
WordPress-Plugin: Show Upload Info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for sharing! this helped me alot!