Riseykins Posted October 28, 2008 Share Posted October 28, 2008 a file called bob.php and I want to use the filename in my file. E.g. <? php include("/home/user/public_html/bob/file.php"); ?> Is there any way to do this? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/130502-solved-using-the-filename-in-an-include/ Share on other sites More sharing options...
DarkWater Posted October 28, 2008 Share Posted October 28, 2008 What do you mean? __FILE__ always contains the filename, if that's what you're asking. Quote Link to comment https://forums.phpfreaks.com/topic/130502-solved-using-the-filename-in-an-include/#findComment-677010 Share on other sites More sharing options...
monkeytooth Posted October 28, 2008 Share Posted October 28, 2008 your example shows you having a directory named bob are you looking to have a variable that would refrence bob and know what directory to goto based of the variable? or have it do the same in concept but with a file name instead? What are you trying to do? Gotta give us a little bit more then your first post to work with if we are to be able to help you Quote Link to comment https://forums.phpfreaks.com/topic/130502-solved-using-the-filename-in-an-include/#findComment-677016 Share on other sites More sharing options...
Riseykins Posted October 29, 2008 Author Share Posted October 29, 2008 I just need it to take the filename and get it to come out within the file. I have many files that are in a directory. Each file corresponds with images located in directories that have the same name as the file. So, when you visit the page bob.php, the images in the directory bob are displayed. If the filename is tim.php then the images in the tim directory show. I can't really explain it any better. :s I need to echo the filename, really. But can I do this inside: <? php include("/home/user/public_html/ECHOFILENAME/file.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/130502-solved-using-the-filename-in-an-include/#findComment-677090 Share on other sites More sharing options...
Brian W Posted October 29, 2008 Share Posted October 29, 2008 Are you dynamically having the includes switch between names? The easiest way would be to get the variable from some where besides the file name. You could parse the URL which would take several steps. Quote Link to comment https://forums.phpfreaks.com/topic/130502-solved-using-the-filename-in-an-include/#findComment-677096 Share on other sites More sharing options...
solon Posted October 29, 2008 Share Posted October 29, 2008 You just need to use <?php include("bob.php"); ?> if the file is in the same directory as the file you want to include it in. If not you just write <?php include("your_directory/bob.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/130502-solved-using-the-filename-in-an-include/#findComment-677233 Share on other sites More sharing options...
Riseykins Posted October 29, 2008 Author Share Posted October 29, 2008 Solon, that's not what I'm trying to do. I'll try and explain again. xD Okay, so say I have the following file: <? php include("/home/user/public_html/FILENAMEHERE/file.php"); ?> If I change the name of the file containing that code to bob, the file automatically does this: <? php include("/home/user/public_html/bob/file.php"); ?> When I change it to jim, it becomes: <? php include("/home/user/public_html/jim/file.php"); ?> I have loads of files that are all identical to each other except for that one thing so it's annoying to have to open each file I make and change it. xD Quote Link to comment https://forums.phpfreaks.com/topic/130502-solved-using-the-filename-in-an-include/#findComment-677464 Share on other sites More sharing options...
bobbinsbro Posted October 29, 2008 Share Posted October 29, 2008 do you mean you want to do something like this? : $foldername = "bob"; //or anything else other than bob include('/home/user/public_html/'.$foldername.'/file.php'); Quote Link to comment https://forums.phpfreaks.com/topic/130502-solved-using-the-filename-in-an-include/#findComment-677481 Share on other sites More sharing options...
Riseykins Posted October 30, 2008 Author Share Posted October 30, 2008 Yeah, it would be something like that. Except that $foldername would need to change when the name of the file changed... Quote Link to comment https://forums.phpfreaks.com/topic/130502-solved-using-the-filename-in-an-include/#findComment-678749 Share on other sites More sharing options...
bobbinsbro Posted October 30, 2008 Share Posted October 30, 2008 to change the contents of a txt file automatically when the filename changes would not be php, it would probably be something in c/c++ running as a process in the background of the OS. it would recognize rename actions, save the address of the file, wait for the rename to complete and then open the file, locate a line starting with include('/home/user/public_html/ and change the next word to the new file name. good luck learning a new language. Quote Link to comment https://forums.phpfreaks.com/topic/130502-solved-using-the-filename-in-an-include/#findComment-678760 Share on other sites More sharing options...
DarkWater Posted October 31, 2008 Share Posted October 31, 2008 to change the contents of a txt file automatically when the filename changes would not be php, it would probably be something in c/c++ running as a process in the background of the OS. it would recognize rename actions, save the address of the file, wait for the rename to complete and then open the file, locate a line starting with include('/home/user/public_html/ and change the next word to the new file name. good luck learning a new language. ...What? <?php $base = basename(__FILE__, '.php'); include("$base/file.php"); ...... Yeah. Quote Link to comment https://forums.phpfreaks.com/topic/130502-solved-using-the-filename-in-an-include/#findComment-679000 Share on other sites More sharing options...
bobbinsbro Posted October 31, 2008 Share Posted October 31, 2008 i was under the impression that he want's the to detect rename (F2) in the OS and change 1 word inside the file automatically... it may be that i'm just really tired. i'm going to bed. good night. Quote Link to comment https://forums.phpfreaks.com/topic/130502-solved-using-the-filename-in-an-include/#findComment-679002 Share on other sites More sharing options...
DarkWater Posted October 31, 2008 Share Posted October 31, 2008 i was under the impression that he want's the to detect rename (F2) in the OS and change 1 word inside the file automatically... it may be that i'm just really tired. i'm going to bed. good night. LOL, good night. And just so you know, my script automatically takes the current filename and parses out everything except the actual name (it even cuts off the extension) so he can directly include() it. Quote Link to comment https://forums.phpfreaks.com/topic/130502-solved-using-the-filename-in-an-include/#findComment-679003 Share on other sites More sharing options...
Riseykins Posted November 1, 2008 Author Share Posted November 1, 2008 DarkWater got it! I knew that it was simple as hell, but as I'm a n00b, I couldn't do it myself! Thank you, all! Quote Link to comment https://forums.phpfreaks.com/topic/130502-solved-using-the-filename-in-an-include/#findComment-679786 Share on other sites More sharing options...
Riseykins Posted November 11, 2008 Author Share Posted November 11, 2008 Here is what I wanted to do: http://burningviolet.com/myspace/Hearts.php http://burningviolet.com/myspace/Peace-Signs.php Yeah, they are horrible but I was trying out a tutorial. Haha. I feel sick. O.o Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/130502-solved-using-the-filename-in-an-include/#findComment-687419 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.