eatc7402 Posted October 14, 2013 Share Posted October 14, 2013 I'm using Win 8, php 5.3.13 on a new pc for the first time. The following simple if test should return EITHER of the choices (or so I do beleive) But when I run it on my new Windiows 8 PC for the first time it does neither. Strange! The line echo "$info_test_file<br><br>" ; does return a correct result but the if test doesn't seem to. ================================ <?phpecho "test<br><br>" ;$info_test_file ="../php/info_test.txt" ;echo "$info_test_file<br><br>" ;if (file_exists($info_test_file)) { echo "<font color=\"#FFFFFF\">File test DOES exist!</font><br />" ; $we_are_local = "1" ;} else { echo "<font color=\"#FFFFFF\">File test DOES NOT exist!</font><br />" ;} ?> ========================= eatc7402 Quote Link to comment Share on other sites More sharing options...
requinix Posted October 14, 2013 Share Posted October 14, 2013 One of those messages will be outputted. If not then there's an error somewhere and your script isn't completely executing. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 14, 2013 Share Posted October 14, 2013 (edited) You are outputting the text in white text color! Is your page background white? echo "<font color=\"#FFFFFF\">File test DOES exist!</font><br />" ; echo "<font color=\"#FFFFFF\">File test DOES NOT exist!</font><br />" If it is white you wont see any thing! Edited October 14, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
.josh Posted October 14, 2013 Share Posted October 14, 2013 wait..you CAN'T see white text on a white background????!!?! This is ridiculous, someone needs to do something about that. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted October 14, 2013 Share Posted October 14, 2013 >It depends on how creative and inquisitive you are. Quote Link to comment Share on other sites More sharing options...
.josh Posted October 14, 2013 Share Posted October 14, 2013 I DON'T C WUT U DID THAR Quote Link to comment Share on other sites More sharing options...
Barand Posted October 14, 2013 Share Posted October 14, 2013 This thread is in real danger of getting silly! Quote Link to comment Share on other sites More sharing options...
Nightasy Posted October 14, 2013 Share Posted October 14, 2013 (edited) Not sure if this is the case here but I have encountered servers where adding a "../" in front of an address causes it to not work at all. You have: $info_test_file ="../php/info_test.txt" ; Just to test, try removing the ../ Like this: $info_test_file ="php/info_test.txt" ; I know it sounds silly but that actually matters on my GoDaddy server. It won't locate files if there is a ../ in front of addresses. Edited October 14, 2013 by Nightasy Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted October 14, 2013 Share Posted October 14, 2013 I know it sounds silly but that actually matters on my GoDaddy server. It won't locate files if there is a ../ in front of addresses. You've gotta be kidding Quote Link to comment Share on other sites More sharing options...
Barand Posted October 14, 2013 Share Posted October 14, 2013 Or it may require the absolute path on the server $info_test_file = realpath("../php/info_test.txt") ; if (file_exists($info_test_file)) { Quote Link to comment Share on other sites More sharing options...
Nightasy Posted October 14, 2013 Share Posted October 14, 2013 (edited) Nope, I'm serious. But I'm also still learning. I always figured there was a reason for it but I just remove the ../ and everything works as a result so I never looked into it. Ya know what, it also occurred to me that the server at my last college had the same issue. I had to remove the ../ on that server too. Edited October 14, 2013 by Nightasy Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted October 14, 2013 Share Posted October 14, 2013 Example, please Quote Link to comment Share on other sites More sharing options...
.josh Posted October 14, 2013 Share Posted October 14, 2013 the path should either be the absolute path on the server, or else a path relative to the script being executed. "../" means "start where the script is being executed and go up one dir level". So based on the path in the OP, that file should be located at: /full/server/path/script.php <-- the script that is running /full/server/php/info_test.txt <-- this is where the file should be, based on the path given what the actual server path is ("/full/server/path/") depends on how the server and file structure is setup. If you are on shared hosting then you likely do not have full root access and as far as your script is concerned, the root dir starts at your account's directory, which is usually the public html directory (usually named htdocs or public or public_html or similar) or one dir level above that. But regardless it will still look for it starting from there. Anyways, point is, the important thing is where it is located relative to the script that is running. Quote Link to comment Share on other sites More sharing options...
Nightasy Posted October 14, 2013 Share Posted October 14, 2013 (edited) Example, please If you are asking me for an example, I suppose this would suffice. This is from the index.php page on my most recent project. <div id="introvideodiv"> <video poster="videos/1.jpg" preload="auto" controls> <source src="videos/placeholder.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /> </video> If you'll notice, I have no ../ in the addresses for the poster and the video. If I add the ../ they won't work at all. No poster would show and no video would be located. My GoDaddy server is a shared server as far as I know and this is probably why I can't add the ../ in the addresses. I just figured I would mention it here because that little issue on my server stumped me for a couple hours when I first got the server through GoDaddy. Now my testing server is WAMP and it requires the ../ so I just do live test now in a password protected section (using sessions) on my server as it became a pain to keep changing that little detail on every page. Needless to say, though, aside from the white text on a white background my only assumption is that the address to the text file is not correct for whatever the reason. Be it the ../ or it needing an absolute path. On a side note however, the issue would also occur if for some reason the php folder is not permitting access. Just brain storming here. Perhaps an issue with the folder permissions or .htaccess restrictions? Edited October 14, 2013 by Nightasy Quote Link to comment Share on other sites More sharing options...
.josh Posted October 14, 2013 Share Posted October 14, 2013 well that's client-side code so "root" means the root public dir that browsers can access. So for example if the page that code is on is http://www.yoursite.com/path/to/page.php and you did this: <video poster="../videos/1.jpg" preload="auto" controls> <source src="../videos/placeholder.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /> </video> the browser would attempt to look for them at http://www.yoursite.com/path/videos/1.jpg and http://www.yoursite.com/path/videos/placeholder.mp4.jpg But, if your page is on http://www.yoursite.com/page.php (the public root), and you prefix with "../" then it will still resolve to the root public dir, so doing "../videos/1.jpg" would be the same as http://www.yoursite.com/videos/1.jpg So basically the page that code is on must not be in the public root; it must have been http://www.yoursite.com/path/to/whatever/page.php and you expected your files to be located at http://www.yoursite.com/path/to/whatever/videos/1.jpg but it resolved to http://www.yoursite.com/path/to/videos/1.jpgso the "../" was indeed messing things up. Quote Link to comment Share on other sites More sharing options...
Nightasy Posted October 14, 2013 Share Posted October 14, 2013 Well, I suppose that explains it. Like I said I never looked into it but yea, my entire site is inside of a folder and uses a splash screen index page at the root. So I guess that explains why I had the issue on my new server and why I had it in college too. In college I had to put my site in a folder due to the way they taught some restrictions with .htaccess and folder permissions. Perhaps this is the case for eatc7402, I'm happy to have learned what you just told me though. I always wondered why that was an issue for my current server (and in my college course too). Learn something new everyday. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted October 14, 2013 Share Posted October 14, 2013 @Nightasy, read this article. Quote Link to comment Share on other sites More sharing options...
Nightasy Posted October 15, 2013 Share Posted October 15, 2013 @Nightasy, read this article. Ah, relative path. I get it. Quote Link to comment Share on other sites More sharing options...
requinix Posted October 15, 2013 Share Posted October 15, 2013 (edited) Ah, relative path. I get it.Actually both of the filenames you had were relative. You can tell because they don't start with a slash (or *:\ for Windows). That ../ matters because you're changing the path to the file. It's as if you had $address = "221B Baker Street"; $address = "21B Baker Street";Only one of them will get you where you want to go. Edited October 15, 2013 by requinix Quote Link to comment Share on other sites More sharing options...
Nightasy Posted October 15, 2013 Share Posted October 15, 2013 (edited) Yea, I completely understand it. In my case, adding a ../ basically leaves out the folder that the page is in, since it is not in the root folder. I completely get it now, I just never looked into why and now I know. Adding a ../ would send it to my root/videos folder instead of the root/folder_my_page_is_in/videos folder. It makes sense. Edited October 15, 2013 by Nightasy Quote Link to comment 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.