The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Creating a widget from this code..
Hi guys, can someone help me please with a beginners PHP problem.
I want to create a widget for my CMS using the following code to list files as links. I'm fine with the basics of creating a widget, but I need a little help please to implement this code. Code:
<?php $count = 0; if ($handle = opendir('./mp3')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") {$count++; print("<a href=\"".$file."\">".$file."</a><br />\n"); } } echo '<br /><br /><a href="..">Return</a>'; closedir($handle); } ?> Thanks for your time. |
#2
|
||||
|
||||
Download a couple of widgets that are posted here and take a look at how they did it. You cannot use print or echo in your widget. You must assign the output to a variable. As I said, if you download a widget or two from the mods area, you will see how it needs to be done.
|
#3
|
|||
|
|||
I'm not a widget expert, but I think if, in place of print() and echo() you use:
PHP Code:
PHP Code:
it might work. ETA: ah, yeah, like Lynne said. |
#4
|
|||
|
|||
Thanks a lot for the help guys, I'm almost there. I'm now using the following code :-
Code:
// Define the full path to your folder from root $path = "./mp3"; // Open the folder $dir_handle = @opendir($path) or die("Unable to open $path"); // Loop through the files while ($file = readdir($dir_handle)) { if($file == "." || $file == ".." || $file == "index.php" ) continue; $output .= "<a href=\"$file\">$file</a><br />"; } // Close closedir($dir_handle); The link displayed is Code:
www.example.com/file.mp3 Code:
www.example.com/mp3/file.mp3 |
#5
|
|||
|
|||
search
Code:
$output .= "<a href=\"$file\">$file</a><br />"; Code:
$output .= '<a href="' . $path . '/' . $file'">' . $file . '</a><br />'; |
#6
|
|||
|
|||
Thanks for the quick response Mooff but I'm afraid that doesn't work.
$path contains the string ./mp3 While this is applicable to denote a path on the server, its not applicable to use as a link. --------------- Added [DATE]1316196988[/DATE] at [TIME]1316196988[/TIME] --------------- OK, for future reference , I got it ! Code:
$output .= "<a href=\"/mp3/$file\">$file</a><br />"; |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|