我想在我的Wordpress中的download.php页面上显示文件大小。有人能帮助我吗?
修改
我发现我可以展示内容(the_content()),作者(the_author())和时间(the_time('Y-m-j H:i'))。我没有找到如何通过这样的函数显示文件大小,而不是我在PHP中搜索答案,但是我的问题因为函数filesize(),没有显示任何东西......我通过我的img url而没有我看不到。我尝试方法file_exists(),但这表明我的文件不存在(uploads \ 2013 \ 05 \ banner.jpg)我确定该文件存在
答案 0 :(得分:1)
在filesize
上使用PHP的attached file path(基于附件ID):
$bytes = filesize( get_attached_file( $post->ID ) );
要转换/格式化值,请使用WP函数size_format
:
$size = size_format( $bytes );
$size = wp_convert_bytes_to_hr( $bytes );
答案 1 :(得分:0)
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div>
<?php if ( has_post_thumbnail()) : ?>
<a href='<?php the_permalink(); ?>' title='<?php the_title_attribute(); ?>'>
<?php if ( has_post_thumbnail()) the_post_thumbnail('small-thumb'); ?></a>
<?php endif;?>
<div>Date: <?php the_time('Y-m-j H:i') ?>, Author: <?php the_author(); ?></div>
<h3><?php the_title(); ?></h3>
<?php the_content(''); ?>
</div>
<?php endwhile; endif; ?>
也许这有帮助。