Can I stick a php readdir script in a Javascript?
I would like to stick a php code (readdir and print links to page) into a Dynamic Ajax Content script like below. Is this even possible as I am getting errors? Any help would be very appreciated.
<a href="javascript:ajaxpage('PHP_SCRIPT_HERE', 'rightcolumn');">TEXT HERE DOES NOT MATTER</a>
This is the PHP script I want to use to scan the directory and print links to page.
<?php
// These files will be ignored
$excludedFiles =开发者_运维百科 array (
'excludeMe.file',
'excludeMeAs.well'
);
// These file extensions will be ignored
$excludedExtensions = array (
'html',
'xslt',
'htm',
);
// Make sure we ignore . and ..
$excludedFiles = array_merge($excludedFiles,array('.','..'));
// Convert to lower case so we are not case-sensitive
for ($i = 0; isset($excludedFiles[$i]); $i++) $excludedFiles[$i] =
strtolower(ltrim($excludedFiles[$i],'.'));
for ($i = 0; isset($excludedExtensions[$i]); $i++) $excludedExtensions[$i] =
strtolower($excludedExtensions[$i]);
// Loop through directory
$dir = 'dir_1/dir_2/';
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
$extn = explode('.',$file);
$extn = array_pop($extn);
// Only echo links for files that don't match our rules
if (!in_array(strtolower($file),$excludedFiles) &&
!in_array(strtolower($extn),$excludedExtensions)) {
$count++;
print("<a href=\"".$dir.$file."\">".$file."</a><br />\n");
}
}
echo '<br />';
closedir($handle);
}
?>
I think you might be missing a html element with the id of rightcolumn?
You need to add a div or some other container on the page with the id of rightcolumn. The script will then populate this container with the output of your php script.
精彩评论