20. april 2007 - 15:56
Der er
1 kommentar
Får fejl "warning filesize"
Jeg har et PHP script, som virker på mit arbejde, men det virker ikke hjemme på min egen server. Mit arbejde kører PHP4, jeg kører PHP5. Scriptet indlæser filer og mapper på et system, og læser filstørrelsen på dem. Jeg får fejlen Warning: filesize() [function.filesize]: stat failed for noget.php in C:\Apache Group\Apache2\htdocs\ekintra\dokumenter\index-indhold.php on line 198 Warning: filectime() [function.filectime]: stat failed for noget.php in C:\Apache Group\Apache2\htdocs\ekintra\dokumenter\index-indhold.php on line 199 Hvor filen noget.php er en af de filer jeg vil have listet op. Scriptet kommer i næste kommentar, som i kan læse her:
Annonceindlæg fra Computerworld
20. april 2007 - 15:57
#1
<?php //phpinfo(); //sætter lige en variabel som referer til siden selv. Istedet for at hardcode fil navnet. $selv = $_SERVER["PHP_SELF"]; if($_REQUEST['dir']) { $dir = $_REQUEST['dir']; $sti = ""; // Første gang sættes link roden print "<a href=\"" . $selv . "?dir=" . $sti . "\">/</a> "; $list = spliti("/", $dir,20); for ($i = 0; count($list) > $i ; $i++) { //Skriver kun et link hvis der findes en værdi i arrayet (split giver altid den første som "") if ($list[$i] <> "" && $list[$i] <> ".") { $sti = $sti . "/" . $list[$i]; print "<a href=\"" . $selv . "?dir=" . $sti . "/\">" . $list[$i] . "/</a> "; } // Sikkerhed for loop og misbrug. if ($i == 100 ) break; } //Skal fjerne.. kun af hensyn til overskuelighed i test fasen. print "<br /><br /><hr /><br /><br />"; } $pdir = $_REQUEST["pdir"]; //$pathdir = str_replace("\", "/", $pathdirtemp); $serverroot = $_SERVER['DOCUMENT_ROOT']; $includepath = $serverroot . "/ekintra/myconf.php"; include($includepath); mysql_connect("localhost",$dbuser,$dbpass) or die(mysql_error()); mysql_select_db("ekintra") or die(mysql_error()); //mysql_query("INSERT INTO fil_metadata (filnavn,beskrivelse) VALUES ('index.php','beskrivelse')"); $sql = "SELECT filnavn, beskrivelse FROM fil_metadata ORDER BY filnavn"; $qh = mysql_query( $sql ) or die( mysql_error() ); $files = array(); while ( $row = mysql_fetch_assoc( $qh ) ) { $files[$row['filnavn']] = $row['beskrivelse']; } function size_hum_read($size){ $i=0; $iec = array(" bytes", " kb", " mb", " gb", "TB", "PB", "EB", "ZB", "YB"); while (($size/1024)>1) { $size=$size/1024; $i++; } return substr($size,0,strpos($size,'.')+4).$iec[$i]; } print "<table border=1>"; print "<tr><td><b>Mappenavn:</b></td></tr>"; if ($_REQUEST['dir']) { $sti = $_REQUEST['dir']; $pdir = $_REQUEST['dir']; $sti = str_replace(".","",$sti); $sti = str_replace('//', '/', $sti); $path = "./" . $sti; $path = str_replace('//', '/', $path); $path2 = "/" . $sti; //Realpath betyder, at jeg laver en URL. //Magicpath betyder, at jeg laver en almindelig Windows sti. $realpath = $path2; $realpath = str_replace('//', '&', $realpath); $realpath = str_replace('&&', '&', $realpath); $realpath = str_replace('&&', '&', $realpath); $realpath = str_replace('&', '/', $realpath); //print ($realpath); $magicpath = $path; $magicpath = str_replace('//', '&', $magicpath); $magicpath = str_replace('&&', '&', $magicpath); $magicpath = str_replace('&&', '&', $magicpath); $magicpath = str_replace('&', '\', $magicpath); $magicpath = str_replace('/', '\', $magicpath); $magicpath2 = getcwd(); $magicpath3 = $magicpath . "\"; $magicpath4 = $magicpath2 . "\" . $magicpath3; } else { $root = "./docs/"; $path = $root; $pdir = $root; $realpath = $root; $magicpath2 = getcwd(); $magicpath4 = $magicpath2; } //$pdir = $_REQUEST['pdir']; print "<br>"; $path = str_replace("./", "./docs/", $path); $path = str_replace("./docs/docs/", "./docs/", $path); $dh = opendir($path); while (($dir = readdir($dh)) !== false) { if ( $dir != "." && $dir != ".." ){ $file = @fopen("$path/$dir", "r"); if (!$file){ $path_and_dir = "$path/$dir"; $path_and_dir = str_replace('//', '/', $path_and_dir); print "<tr>"; print "<td><a href='$selv?dir=$path_and_dir'>$dir</a></td>"; print "</tr>"; } } } closedir($dh); print "</table>"; print "<br>"; print "<table border=1>"; print "<tr><td><b>Filnavn:</b></td><td><b>Størrelse:</b></td><td><b>Oprettet:</b></td><td><b>Beskrivelse:</b></td><td> </td></tr>"; $dh = opendir($path); while (($dir = readdir($dh)) !== false) { if ( $dir != "." && $dir != ".." ){ $file = @fopen("$path/$dir", "r"); if ($file){ $filstorrelse = size_hum_read(filesize($dir)); $filtid = date("F d Y H:i:s.",filectime($dir)); //$pathdirtemp = $path."\".$dir; $magicpath4 = stripslashes($magicpath4); $dotslash = "\." . "\"; $magicpath4 = str_replace($dotslash, "", $magicpath4); $magicpath4 = str_replace("\", "", $magicpath4); $pathdir = $magicpath4 . $dir; //print ($pathdir); $pathdirtemp = $path."\".$dir; $standarddir = "/ekintra/dokumenter"; $filbeskrivelse= "<td>$files[$pathdir]</td>"; print "<tr>"; print "<td><a href='$standarddir$realpath/$dir'>$dir</a></td>"; print "<td>$filstorrelse</td><td>$filtid</td>$filbeskrivelse<td><a href='ret_beskrivelse.php?filnavn=$pathdir&pdir=$pdir'>Ret beskrivelse</a></td>"; //$filbeskrivelse = "hallo"; } print "</tr>"; } } closedir($dh); print "</table>"; ?>