P3t3r Posted December 24, 2007 Share Posted December 24, 2007 I wondered if it was possible to do the following: when one includes "subdir/file.php" and that file doesn't exist, the file "../folder0/subdir/file.php" is included instead. Is that possible? How? This doesn't look like it can be solved with a .htaccess trick, but I don't see how it can be solved. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/83002-include-on-missing-files/ Share on other sites More sharing options...
PHP_PhREEEk Posted December 24, 2007 Share Posted December 24, 2007 You can do an if/else test using file_exists() PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/83002-include-on-missing-files/#findComment-422162 Share on other sites More sharing options...
trq Posted December 24, 2007 Share Posted December 24, 2007 You should always know where includes are and that they exist, but anyway... <?php if (file_exists('subdir/file.php')) { include 'subdir/file.php'; } elseif (file_exists('../folder0/subdir/file.php') { include '../folder0/subdir/file.php'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83002-include-on-missing-files/#findComment-422163 Share on other sites More sharing options...
P3t3r Posted December 24, 2007 Author Share Posted December 24, 2007 You can do an if/else test using file_exists()Not an option in my case, since I'm using a ton of files that already have include() everywhere. It's an impossible work to go replace them all. I'd really need to make include() do this, somehow. It might be impossible of course... Quote Link to comment https://forums.phpfreaks.com/topic/83002-include-on-missing-files/#findComment-422164 Share on other sites More sharing options...
trq Posted December 24, 2007 Share Posted December 24, 2007 Not an option in my case, since I'm using a ton of files that already have include() everywhere. It's an impossible work to go replace them all. You could add the paths to the files into your include_path. See set_include_path(). Quote Link to comment https://forums.phpfreaks.com/topic/83002-include-on-missing-files/#findComment-422166 Share on other sites More sharing options...
P3t3r Posted December 24, 2007 Author Share Posted December 24, 2007 You could add the paths to the files into your include_path. See set_include_path(). Oh, this is interesting. I looked on php.net for a similar function but didn't find one. The syntax of this command isn't entirely clear though, it should be of this form to do what I described above, right? $fullpath = dirname(__FILE__); $newpath = str_replace("folder83","folder0",$fullpath); set_include_path($fullpath.':'.$newpath); providing my script is in /var/www/vhosts/domain.com/httpdocs/folder83 and my files in /var/www/vhosts/domain.com/httpdocs/folder0(/subdir) Now, often my files are included as include("./file.php"); How should I configure the path to cover these too? (include ../folder0/file.php instead) Quote Link to comment https://forums.phpfreaks.com/topic/83002-include-on-missing-files/#findComment-422188 Share on other sites More sharing options...
chantown Posted December 24, 2007 Share Posted December 24, 2007 there's a file exists function in php Quote Link to comment https://forums.phpfreaks.com/topic/83002-include-on-missing-files/#findComment-422197 Share on other sites More sharing options...
P3t3r Posted December 24, 2007 Author Share Posted December 24, 2007 there's a file exists function in phpOf course... but as pointed out above, after it being suggested twice before you, that doesn't help in this case. The actual inclusion code is given, I can only modify what include() does. And the set_include_path was a good suggestion, I just need to know now how to configure it to include(./../folder0/file.php) when (./file.php) is called but nonexistent. Quote Link to comment https://forums.phpfreaks.com/topic/83002-include-on-missing-files/#findComment-422198 Share on other sites More sharing options...
P3t3r Posted December 24, 2007 Author Share Posted December 24, 2007 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/83002-include-on-missing-files/#findComment-422344 Share on other sites More sharing options...
predator Posted December 24, 2007 Share Posted December 24, 2007 there's a file exists function in phpOf course... but as pointed out above, after it being suggested twice before you, that doesn't help in this case. alrite mate he was only trying to help no need to snap back at him. anyway why will the file not exist that you are including? can u elaberate a little more Quote Link to comment https://forums.phpfreaks.com/topic/83002-include-on-missing-files/#findComment-422346 Share on other sites More sharing options...
P3t3r Posted December 24, 2007 Author Share Posted December 24, 2007 Sorry. I'll elaborate a bit more. I have a lot of subfolders (call them httpdocs/forum1,httpdocs/forum2,...,httpdocs/forum10 for simplicity), which are all running more or less the same software (95% of the files are identical in every folder). This means I have to update 10 boards every time I want to change something. Since they only differ in a few files, I would like to make a "httpdocs/forum0" folder which has the standard files, and then delete all unmodified files from the /forum1,...,/forum10 folders. Then, my intention is that when e.g. include("./includes/include1.php"); is called, the following happens (without using file_exists(), the include statement include("./file.php"); is given): -> if ./includes/include1.php exists, include it -> otherwise, include (./../forum0/includes/include1.php) instead. Quote Link to comment https://forums.phpfreaks.com/topic/83002-include-on-missing-files/#findComment-422352 Share on other sites More sharing options...
predator Posted December 29, 2007 Share Posted December 29, 2007 surly then if you are makin a "template" folder as it were called forum0 to run all these on the other folders you could use the file_exist function? Regards Mark Quote Link to comment https://forums.phpfreaks.com/topic/83002-include-on-missing-files/#findComment-425240 Share on other sites More sharing options...
PFMaBiSmAd Posted December 29, 2007 Share Posted December 29, 2007 The OP continued this problem in a new thread and this thread is actually dead or should be merged with the new thread. Quote Link to comment https://forums.phpfreaks.com/topic/83002-include-on-missing-files/#findComment-425274 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.