Jul 26, 2008

Include Help

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Include Help

palli
Need help to include this, i am trying to include this folder
http://www.koddinn.com/shoutbox_v1.2/shoutbox.php to this http://www.koddinn.com/test.php

the folder include many files
http://www.koddinn.com/shoutbox_v1.2

i want to include all the files in a certain directory. do i use reddir for this, how can i do this

CODE
echo "<PRE>";
$handle = opendir(".");
while($file = readdir($handle)) {
if(is_dir($file)) echo "$file/\n";
else echo "$file\n";
}
closedir($handle);
echo "</PRE>";


do i have to loop to include each file.

??

Reply

round
I don't think you can include a whole folder. I think you can work it out so that your directory list is included like a config file that gets updated when your directory is changed(when files are deleted or created. I would love to help but don't have time right now. If you look on php.net you might be able to something there that might help you out.
round

Reply

Spectre
I would recommend going with round's suggestion. A folder may contain other files that you do not wish to include, such as, for example, .htaccess. Having a configuration file which explicitly specifies which files to include might take a little longer to put together, but would be a much better idea overall.

Reply

no9t9
$dh = opendir("shoutbox_v1.2");
while ($temp=readdir($dh)) { if ($temp!="." && $temp!="..") { include($temp); }}

this will include all files in your "shoutbox_v1.2" directory. IF you want to skip certain files, just add them in the IF condition. Right now, the if condition skips "." and ".." because those are not files.

You also might want to add $temp!=".htaccess" as well...

you can also exclude (or include) files using string functions like eregi and strstr. For example, if you only want to include .php files you only need 1 condition in the if statement.

example: if (eregi("\.php",$temp)) will only include php files from the directory "shoutbox_v1.2"

another example: if (eregi("\.php",$temp) || eregi("\.html",$temp)) will include all .php files and .html files

anyway, modify the if condition to do what you want it to.

 

 

 


Reply

no9t9
no edit button...

you might have to add the directory in front of the $temp variable for your include statement.

include ("shoutbox_v1.2/".$temp);

this depends on where you call this script. IF it is within the shoutbox_v1.2 directory, you don't need it. If it is in the root (which your original post suggests), you will need it.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics
Looking for include

Searching Video's for include
advertisement



Include Help



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE