Page 1 of 1

Confused

Posted: Wed Feb 27, 2008 3:57 pm
by LespaulGuy86
Ok, I'm having trouble with the following code.

I'm trying to get it to cycle through all the files in a folder and generate a link based on the filenames that launches a javascript function. However, when I load it into mozilla firefox, I just get a white screen.

Here's the broken code.

<?php
$filePath='\news\';
$dir=opendir($filePath);
While (false !== ($file=readdir($dir))){
echo "<br />";
echo '<a href="javascript:toggleLayer(\' '.$file.'\');">testing</a>';
}
closedir($dir);

?>

The following code works, creates the link, and will launch the java script, but doesn't allow me to pass parameters to the script.

<?php
$filePath='\news\';
$dir=opendir($filePath);
While (false !== ($file=readdir($dir))){
echo "<br />";
echo "<a href=\"javascript:toggleLayer();\">$file</a>";
}
closedir($dir);

?>

And the following code works on a seperate page that I made just for testing.

<?php
$file='testing';
echo '<a href="javascript:toggleLayer(\''.$file.'\');">testing</a>';

?>

So what am I missing? Any help at all would be greatly appreciated. Thanks so much!

Re: Confused

Posted: Wed Feb 27, 2008 4:39 pm
by EverLearning
Your code is giving you a white page, because it has syntax error in it:

Code: Select all

$filePath='\news\';
should be

Code: Select all

$filePath='\news\\';
You had escaped single quote, and the string was not closed so php couldn't parse the file.
And by the way, in filepaths use forwardslash '/', it will be interpreted properly, even on windows. :)
Once that is corrected, it should work(it worked for me).
When developing scripts always turn error reporting on with E_ALL set, so when your scripts dies for whatever reason, you'll have some clue :)

Re: Confused

Posted: Thu Feb 28, 2008 9:43 am
by LespaulGuy86
thanks so much...I'll try it!