Last active
December 26, 2015 09:39
-
-
Save Ikaring/7131421 to your computer and use it in GitHub Desktop.
WordPress shortcode for retrieving (pdf or any) file size.
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 | |
// [filesize file="filename.pdf"] | |
function get_file_size($atts) { | |
extract(shortcode_atts(array( | |
'file' => '', | |
), $atts)); | |
//pdfの置き場所にあわせてパスを設定 | |
$mfile=WP_CONTENT_DIR."/pdf/".$file; | |
if ( is_file($mfile) ){ | |
$filesize = size_format( filesize($mfile) ); | |
} else { | |
$filesize="ファイルがみつかりません"; | |
} | |
return $filesize; | |
} | |
add_shortcode('filesize', 'get_file_size'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've made a plugin for this purpose.
https://wordpress.org/plugins/get-filesize-shortcode/