PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I need to be able to scan a folder for its contents and then output this to a file which flash can then grab a variable from.
I can get it to scan the folder, grab the contents and output it.
The problem lies with line 8 (i think). I need to add 'THE_DIR' variable with the filename to so that it read ./music/filename rather than just ./filename.
<?php
//define constants as constants... (at top of file, makes it easier to read!)
define('THE_FILENAME', './music/text.txt'); //defines the output file
define('THE_DIR', './music/'); //Defines the path to the folder we wish to catalog
$dir=opendir(THE_DIR);
$files=array();
while (($file=readdir($dir)) != false)
$file="$THE_DIR . " " . $file"
array_push($files, $file);
closedir($dir);
sort($files);
$handle = fopen(THE_FILENAME, 'w');
foreach ($files as $file)
{
$out = "<A href='$file'>$file</a><BR>";
echo $out; //output to screen
fputs($handle, $out); //output to file
}
fclose($handle);
?>
For one thing, your quotes seem wrong to me. For one, you forgot ; at the end, plus I think a few more periods are needed. Try this out and see if it works:
theda wrote:For one thing, your quotes seem wrong to me. For one, you forgot ; at the end, plus I think a few more periods are needed. Try this out and see if it works:
Note: You've defined 'THE_DIR' so its a constant, not a variable. You don't use '$' with constants and you don't put constants inside quotation marks. You can directly concatenate a string variable with a string constant, so there's no need for any quotes in this example.
$file = $THE_DIR.$file; // without quotes or
$file "{$THE_DIR}$file"; // without quotes (and braces to limit possible "greediness"
$file "$THE_DIR"."$file"; // with quotes and concatenation
In your original you had the concatentation operation ('.') inside the quotes, not between the two strings.