newbiePHP Posted June 12, 2008 Share Posted June 12, 2008 Hey guys, I have a engine that finds a file in a directory and opens it. The file i want to open is in C:\temp. The PHP file is located in C:\wamp\www. In the code when i set the directory to C:/temp/. The program runs fine. When I set the directory to ../../temp/ it doesn't run. In order to go up a directory is the command ../ and do I need to import something to make it work? Thanks for any help!! Quote Link to comment https://forums.phpfreaks.com/topic/109937-moving-up-a-directory-code/ Share on other sites More sharing options...
jonsjava Posted June 12, 2008 Share Posted June 12, 2008 I tested it using XAMPP, and it worked just fine for me: HTDOC ROOT: c:\xampp\htdocs\jobsite2\test.php test file: c:\Temp\test.php CONTENTS OF jobsite2/test.php: <?php $server_root = "../../../temp/"; include($server_root."test.php"); ?> CONTENTS OF temp/test.php: <?php print "it worked!"; ?> OUTPUT RECEIVED: it worked! So, my test worked fine. I don't see why you would have any issues doing the same. Quote Link to comment https://forums.phpfreaks.com/topic/109937-moving-up-a-directory-code/#findComment-564143 Share on other sites More sharing options...
newbiePHP Posted June 12, 2008 Author Share Posted June 12, 2008 jonsjava, thanks for the reply. Would the fact that i'm running it through firefox be a problem? Quote Link to comment https://forums.phpfreaks.com/topic/109937-moving-up-a-directory-code/#findComment-564146 Share on other sites More sharing options...
jonsjava Posted June 12, 2008 Share Posted June 12, 2008 It's server side. that won't matter. Quote Link to comment https://forums.phpfreaks.com/topic/109937-moving-up-a-directory-code/#findComment-564148 Share on other sites More sharing options...
newbiePHP Posted June 12, 2008 Author Share Posted June 12, 2008 I tried compling it through the cmd and it gave this error '..' is not recognized as an internal or external command, operable program or batch file. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/109937-moving-up-a-directory-code/#findComment-564152 Share on other sites More sharing options...
jonsjava Posted June 12, 2008 Share Posted June 12, 2008 can you post your code, please? Quote Link to comment https://forums.phpfreaks.com/topic/109937-moving-up-a-directory-code/#findComment-564153 Share on other sites More sharing options...
newbiePHP Posted June 12, 2008 Author Share Posted June 12, 2008 If i were to change the $directory to "C:/Temp" It works fine. <?php $FindFile = "Example"; $directory = '../../Temp/'; //trailing slash $flag = false; $ext = array( '.jpg' , '.gif' , '.txt' ); for( $i = 0; count( $ext ) > $i; $i++ ) { if( file_exists( $directory . $FindFile . $ext[$i] ) ) { $flag = true; $name = $directory . $FindFile . $ext[$i]; break; } } if( $flag == true ) { exec($name); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/109937-moving-up-a-directory-code/#findComment-564158 Share on other sites More sharing options...
jonsjava Posted June 12, 2008 Share Posted June 12, 2008 you're trying to run an image? I did a slight mod of your script (changed example to test, had it go one more level up, and have it print the name of the file instead of executing it): <?php $FindFile = "test"; $directory = '../../../Temp/'; //trailing slash $flag = false; $ext = array( '.php', '.jpg' , '.gif' , '.txt' ); for( $i = 0; count( $ext ) > $i; $i++ ) { if( file_exists($directory.$FindFile.$ext[$i] ) ) { $flag = true; $name = $directory . $FindFile . $ext[$i]; break; } } if( $flag == true ) { print $name; } ?> it worked, for what it is. Only problem I see is you can't just exec($name); because going off the script you posted, you're trying to execute an image. Windows (as well as linux, and every other system in the world) can't execute an image. You also can't execute a php file in windows, unless your system knows how to execute a .php extension. Quote Link to comment https://forums.phpfreaks.com/topic/109937-moving-up-a-directory-code/#findComment-564165 Share on other sites More sharing options...
newbiePHP Posted June 12, 2008 Author Share Posted June 12, 2008 No example is a text file and the whole program runs fine and opens that text file when the directory is set to C:/temp I just have those other extensions as options to play around with if i get .txt working. Thanks for the info about the images though. I don't really see any difference between your script and mine so can't figure out why yours works and mine doesn't. Do you know what this error means? '..' is not recognized as an internal or external command, operable program or batch file Quote Link to comment https://forums.phpfreaks.com/topic/109937-moving-up-a-directory-code/#findComment-564181 Share on other sites More sharing options...
jonsjava Posted June 12, 2008 Share Posted June 12, 2008 it means that it's trying to run the ".." as if it were a file, not a directory structure. Quote Link to comment https://forums.phpfreaks.com/topic/109937-moving-up-a-directory-code/#findComment-564183 Share on other sites More sharing options...
newbiePHP Posted June 12, 2008 Author Share Posted June 12, 2008 Do you have some sort of special settings that allows your compiler to recongise it as a directory rather than a file? Thanks for all the help by the way Quote Link to comment https://forums.phpfreaks.com/topic/109937-moving-up-a-directory-code/#findComment-564186 Share on other sites More sharing options...
wildteen88 Posted June 12, 2008 Share Posted June 12, 2008 PHP does not compile scripts. How are you getting the following error: '..' is not recognized as an internal or external command, operable program or batch file This is not an error from PHP itself but a Windows command error. Which suggests to me that you are not actually passing the code to the PHP interpreter. Quote Link to comment https://forums.phpfreaks.com/topic/109937-moving-up-a-directory-code/#findComment-564299 Share on other sites More sharing options...
jonsjava Posted June 12, 2008 Share Posted June 12, 2008 oops, I should have explained what I meant by "it". sorry for the confusion. Quote Link to comment https://forums.phpfreaks.com/topic/109937-moving-up-a-directory-code/#findComment-564308 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.