使用EXEC-PHP在wordpress中显示已排序的
我在写WordPress的博客。以前的开发人员使用“execphp”在某个页面中执行PHP脚本使用EXEC-PHP在wordpress中显示已排序的,php,function,wordpress,Php,Function,Wordpress,我在写WordPress的博客。以前的开发人员使用“execphp”在某个页面中执行PHP脚本 http://url-of-the-page/包含在“/homez.406/xxx/www/wp content/xxx/xxx/”中的文件列表 我想按日期订购文件,但我不知道怎么做! 有人用过这个吗 <!--?php showContent('/homez.406/xxx/www/wp-content/xxx/xxx/','http://url-of-the-page/',false,fals
http://url-of-the-page/
包含在“/homez.406/xxx/www/wp content/xxx/xxx/”中的文件列表
我想按日期订购文件,但我不知道怎么做!
有人用过这个吗
<!--?php showContent('/homez.406/xxx/www/wp-content/xxx/xxx/','http://url-of-the-page/',false,false); ?-->
这是我在functions.php中找到的
function showContent($path,$webpath,$adminclear,$adminup){
if ($handle = opendir($path))
{
if ($adminclear==true)
{
global $user_ID; if( $user_ID ) :
if( current_user_can('level_10') ) :
$auth=true;
else :
$auth=false;
endif;
endif;
}
if ($adminup==true)
{
global $user_ID; if( $user_ID ) :
if( current_user_can('level_10') ) :
$authup=true;
else :
$authup=false;
endif;
endif;
}
else{$auth=true;$authup=true;}
if ((isset($_POST['dlfile']))&&($auth==true))
{
$removefile=$_POST['dlfile'];
unlink ($removefile);
}
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$fName = $file;
$goodpath=$webpath.$fName;
$file = $path.$file;
$abpath=$path.$fName;
if(is_file($file)) {
echo "<p><a href='http://www.otrmd.com/wp-content/themes/FactoryWP/dl.php?p=".$goodpath."&f=".$fName."'>".$fName."</a><br/> Uploaded on ".date ('d-m-Y H:i:s', filemtime($file))."<br/>Size: ".filesize($file)." bytes</p>";
if($auth==true)
{
echo "<form method='post' action=".$_SERVER['REQUEST_URI'].">
<input type='hidden' name='dlfile' value='".$abpath."'>
<input type='submit' value='Clear File'>
</form><br/>";
}
} elseif (is_dir($file)) {
print "<p><a href='".$_SERVER['PHP_SELF']."?path=$file'>$fName</a></p><br/><br/>";
}
}
}
closedir($handle);
}
if ($authup==true)
{
echo ("[uploadify folder='".$path."' multi=true]");
}
}
函数showContent($path、$webpath、$adminclear、$adminup){
如果($handle=opendir($path))
{
如果($adminclear==true)
{
全局$user\u ID;如果($user\u ID):
如果(当前用户可以(“10级”):
$auth=true;
其他:
$auth=false;
endif;
endif;
}
如果($adminup==true)
{
全局$user\u ID;如果($user\u ID):
如果(当前用户可以(“10级”):
$authup=true;
其他:
$authup=false;
endif;
endif;
}
else{$auth=true;$authup=true;}
if((isset($\u POST['dlfile'])&($auth==true))
{
$removefile=$_POST['dlfile'];
取消链接($removefile);
}
while(false!=($file=readdir($handle)))
{
如果($file!=“&&&$file!=”)
{
$fName=$file;
$goodpath=$webpath.$fName;
$file=$path.$file;
$abpath=$path.$fName;
if(is_文件($file)){
echo“
上载于“.date('d-m-Y H:i:s',filemtime($file))。”
大小:“.filesize($file)。“bytes”;
如果($auth==true)
{
回声“
“;
}
}elseif(is_dir($file)){
打印“
”;
}
}
}
closedir($handle);
}
如果($authup==true)
{
echo(“[uploadify folder=””。$path.“'multi=true]”);
}
}
这里的问题是使用了函数readdir
,文档上说:
条目按文件系统存储的顺序返回。
因此,我建议使用scandir
和uasort
组合,按filemtime
替换
while (false !== ($file = readdir($handle)))
借
并在脚本开头声明以下回调函数
function sort_by_filemtime($file1, $file2) {
global $path;
$file1mtime = filemtime($path.$file1);
$file2mtime = filemtime($path.$file2);
if ($file1mtime == $file2mtime) {
return 0;
}
return $file1mtime > $file2mtime ? 1 : -1;
}
我们可以看到
showContent()
函数的代码吗?在这里。无法显示“真实”url,但没关系,我想我很确定mexique1是指showContent()
函数中的代码。就目前情况而言,这个问题与您如何显示文件无关,因此我们无法真正帮助您。=)好的,我已经查看了function.php,我已经更新了我的问题。我现在还没有机会尝试它(忙于其他工作)。这个周末我会试试的!
function sort_by_filemtime($file1, $file2) {
global $path;
$file1mtime = filemtime($path.$file1);
$file2mtime = filemtime($path.$file2);
if ($file1mtime == $file2mtime) {
return 0;
}
return $file1mtime > $file2mtime ? 1 : -1;
}