PHP - 来自dir的最新文件无效

时间:2013-11-21 17:51:58

标签: php image file directory wamp

我正在使用这个脚本:

<?php

$path = "/cam/video/INDOOR/grabs/"; 
$sirka = "640";
$vyska = "480";

$latest_ctime = 0;
$latest_filename = '';    
$d = dir($path);
while (false !== ($entry = $d->read())) {
  $filepath = "{$path}/{$entry}";
  // could do also other checks than just checking whether the entry is a file
  if (is_file($filepath) && filectime($filepath) > $latest_ctime) {
    $latest_ctime = filectime($filepath);
    $latest_filename = $entry;

  }
}

echo '<a href=';
print ($path);
print ($latest_filename);
echo ' target="_blank"><img style="border: 0px solid ; width: ';
print ($sirka);
echo 'px; height: ';
print ($vyska);
echo 'px;" src="';
print ($path);
print ($latest_filename);
echo '"</a> ';

?>

它应该显示来自$ path的最新ptohot $ sirka是width atribute,$ vyska是height atribute fot image

我正在使用WAMP的实际版本,但没有发生任何事情:/它曾经在我使用旧版本时工作。你能帮助我吗?谢谢

//编辑:

我找到了

我添加了$ _SERVER ['DOCUMENT_ROOT']。到$ path

$path = $_SERVER['DOCUMENT_ROOT'].'/cam/video/INDOOR/grabs/'; 

1 个答案:

答案 0 :(得分:0)

不确定您的问题,但如果网络服务器用户具有/cam/video/INDOOR/grabs/的读取权限,请尝试:

array_multisort($times = array_map('filectime', $files = glob("$path/*.*")), SORT_DESC, $files);
$latest_ctime = $times[0];
$latest_filename = files[0];