wendu Posted August 7, 2009 Share Posted August 7, 2009 hey a newb question how can I with PHP handle files that are in different folders? currently, when I'm inside temp and need to reference the folder that contains temp, and a file in it, I use ../index.php but sometimes it's not known at what level I am, so I could do a full reference, like http://example.com/index.php but that's not very wise I'm told also, depending on the platform, I cannot use /index.php because that might not always be the root, where the Web content is Quote Link to comment https://forums.phpfreaks.com/topic/169241-handling-files-from-different-folders/ Share on other sites More sharing options...
Lamez Posted August 7, 2009 Share Posted August 7, 2009 I am a bit lost on your question. You can call files from different folders with php, and include them in the current script. Such as: <?php //in current dir. include("file.php"); //up a folder, a in the folder name: folder_name include("../folder_name/file.php"); ?> Maybe you can rephrase your question. -Lamez Quote Link to comment https://forums.phpfreaks.com/topic/169241-handling-files-from-different-folders/#findComment-893042 Share on other sites More sharing options...
wendu Posted August 7, 2009 Author Share Posted August 7, 2009 Certainly! because I'm using SSI, and have includes (php requires) I can't change those includes when I go up a directory or down a directory, it has to know itself where I'm currently calling it from, and based on that make linkes to ROOT/contact.php work (instead of ROOT/temp/contact.php) Quote Link to comment https://forums.phpfreaks.com/topic/169241-handling-files-from-different-folders/#findComment-893051 Share on other sites More sharing options...
ldougherty Posted August 7, 2009 Share Posted August 7, 2009 Depending what you are trying to do with the referenced file you can either call it via a full path or referenced path. If you are in /var/temp and you you need to access /var/file.txt you can either reference it is ../file.txt or /var/file.txt If the file(s) are web accessible you could use the URL like for linking images. Quote Link to comment https://forums.phpfreaks.com/topic/169241-handling-files-from-different-folders/#findComment-893054 Share on other sites More sharing options...
wendu Posted August 7, 2009 Author Share Posted August 7, 2009 Depending what you are trying to do with the referenced file you can either call it via a full path or referenced path. If you are in /var/temp and you you need to access /var/file.txt you can either reference it is ../file.txt or /var/file.txt If the file(s) are web accessible you could use the URL like for linking images. that's whaat I thought, so I need to use full reference. it's okay, really. Quote Link to comment https://forums.phpfreaks.com/topic/169241-handling-files-from-different-folders/#findComment-893061 Share on other sites More sharing options...
wildteen88 Posted August 7, 2009 Share Posted August 7, 2009 You can always do something like this define('ROOT', $_SERVER['DOCUMENT_ROOT']); include ROOT . '/path/to/file.php'; Quote Link to comment https://forums.phpfreaks.com/topic/169241-handling-files-from-different-folders/#findComment-893064 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.