stevieontario Posted April 5, 2014 Share Posted April 5, 2014 Morning Freaks, Wierd little problem -- I have set up xampp sandboxes on two different computers. On one, the following script finds an xml file inside a folder and var_dump() outputs info about the file. On the other, nothing. <?php include "Functions1.php"; include "Functions2.php"; $filemoniker = '/home/ubuntu/public_html/myfolder/xmlfile.xml'; if (file_exists($filemoniker)) {echo "The file $filemoniker exists";} else {echo "The file $filemoniker does not exist";} foreach(glob('/home/ubuntu/public_html/myfolder/xmlfile.xml') as $filename) { $xmlname = basename($filename); echo "<pre>"; echo $xmlname; echo "</pre>"; $xml_file = simplexml_load_file($filename) or die("no data loaded"); $rr = object2array($xml_file); print "<pre>"; var_dump($rr); print "</pre>"; } ?> As you can see, I wrote in a test script on lines 5-7. On one sandbox -- php version 5.4.7 -- that script echoes "The file [$filemoniker] exists." In the second sandbox -- php v. 5.5.9 -- it echoes "The file [$filemoniker] does not exist." I have checked the paths and the folder myfolder, and the file does exist. Needless to say, the rest of the script from foreach down returns nothing but a blank screen. Any ideas? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted April 5, 2014 Share Posted April 5, 2014 So on both sandboxes the path is exactly the same for the xml file? And both sandboxes have the same operating environment except for the PHP version installed? Quote Link to comment Share on other sites More sharing options...
stevieontario Posted April 5, 2014 Author Share Posted April 5, 2014 Ch0cu3r, sort of. The home folders have different names but the paths are the same. When I run the script without the xmlfile name -- i.e. just the path -- then the 5.5.9 sandbox returns "The file [$filemoniker] exists."So it appears that the 5.5.9 sandbox just won't recognize the files inside the folder. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted April 5, 2014 Share Posted April 5, 2014 It maybe a file permission issue. PHP may not be able to read that file. Quote Link to comment Share on other sites More sharing options...
stevieontario Posted April 5, 2014 Author Share Posted April 5, 2014 I wondered about that, and tried on the basis of searches for fixes to similar problems to use eio_chmod('/home/ubuntu/public_html/myfolder/', 0777); which returned "Fatal error: Call to undefined function eio_chmod()". Tried chmod('/home/ubuntu/public_html/myfolder/', 0777); which returned "The file [$filemoniker] does not exist." Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted April 5, 2014 Share Posted April 5, 2014 I meant the file permission for the xml file itself, not for your directory. Judging by your last comment When I run the script without the xmlfile name -- i.e. just the path -- then the 5.5.9 sandbox returns "The file [$filemoniker] exists." PHP can access the directory just fine. The problem lies with PHP unable to read the xml file itself which is causing file_exists to return false and so your get the xml file does not exist message. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 5, 2014 Share Posted April 5, 2014 i'm going to guess the actual filename is different in the code from what the actual filename is, either the spelling or CAPitalization or you might even have some white-space character(s) as part of the actual filename. Quote Link to comment Share on other sites More sharing options...
stevieontario Posted April 5, 2014 Author Share Posted April 5, 2014 well, I copied the file name (first from the Ubuntu folder and then from the Linux terminal, just to be sure) and pasted it into the code. Neither works. It recognizes the path, but doesn't see the files inside. Should have mentioned before, in case it matters: the sandbox in which the script runs fine is installed in Ubuntu 11.10; the wonky one is in Ubuntu 12.04. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 5, 2014 Share Posted April 5, 2014 see is php will tell you why it cannot find/access the file. make sure php's error reporting is full on, add the following two lines of code immediately after your first opening php tag - ini_set("display_errors", "1"); error_reporting(-1); Quote Link to comment Share on other sites More sharing options...
trq Posted April 5, 2014 Share Posted April 5, 2014 Besides your file not found issue, I don't see the point of the call to glob and then the subsequent foreach. Passing glob the path to a single file will only return a single result. Quote Link to comment Share on other sites More sharing options...
stevieontario Posted April 5, 2014 Author Share Posted April 5, 2014 trq, you are right there seems to be no point for the foreach. That part of the script is a historical vestige of my original problem. The folder myfolder actually holds thirty or forty of xml files. Works fine in Ubuntu 11.10 with PHP 5.4.7. But on my Ubuntu 12.04 system with PHP 5.5.9 the foreach was not yielding any of the info I wanted. So I backtracked and tried file_exists() just to see if PHP was recognizing anything in that folder. I copied/pasted one of the files into the code just to be sure. mac, I did as suggested and put the ini_set code right after the opening tag and got the same result. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 6, 2014 Share Posted April 6, 2014 there's got to be something going on with the actual filename. how about doing a var_dump() of what glob('/home/ubuntu/public_html/myfolder/*.*') returns. Quote Link to comment Share on other sites More sharing options...
stevieontario Posted April 6, 2014 Author Share Posted April 6, 2014 mac -- I ran this code: <?php ini_set("display_errors", "1"); error_reporting(-1); $filemoniker = '/home/ubuntu/public_html/myfolder/*.*'; $filetest = glob($filemoniker); var_dump($filetest); ?> and got this: array(0) { } Quote Link to comment Share on other sites More sharing options...
boompa Posted April 6, 2014 Share Posted April 6, 2014 What is the ownership and permissions of the myfolder directory? Does the user under which PHP/your web server is running have execute permissions on the myfolder directory? Quote Link to comment Share on other sites More sharing options...
stevieontario Posted April 7, 2014 Author Share Posted April 7, 2014 drwx--- on myfolder; -rw-rw-rw- on its contents Quote Link to comment Share on other sites More sharing options...
trq Posted April 7, 2014 Share Posted April 7, 2014 And who owns myfolder ? It is restricted to being read only by its owner. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 7, 2014 Share Posted April 7, 2014 Sounds like UserDir mapping directive in apache is not enabled on the second machine.To enabe UserDir open up the apache conf file and change UserDir disable to UserDir public_html and restart the http server, then all requests from the browser to the http server and all php searching functions should be work. The URL request from the browser would be something like - http://example.com/~username/myfolder/test.xml Quote Link to comment Share on other sites More sharing options...
stevieontario Posted April 7, 2014 Author Share Posted April 7, 2014 thanks everyone for your help. What a puzzle. trq, I own myfolder (at least I think I do)... I own the computer and aside from a user account I set up for my girlfriend I'm the only user. Jazzman -- I assume you mean "httpd-userdir.conf"? There are two of them in my system for some reason. (The file "httpd.conf" refers to this file in the userdir section.) But neither indicated that UserDir has been disabled. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 7, 2014 Share Posted April 7, 2014 Don't touch/edit anything if you don't know exactly what you are doing. Are you able to make a request by the browser to that user specific directory/file. Something like - localhost/~ubuntu/myfolder/file Quote Link to comment Share on other sites More sharing options...
stevieontario Posted April 7, 2014 Author Share Posted April 7, 2014 (edited) I put "localhost/ubuntu/myfolder" into the browser address bar, hit Enter, and got: Access forbidden!You don't have permission to access the requested object. It is either read-protected or not readable by the server. If you think this is a server error, please contact the webmaster.Error 403 localhostApache/2.4.7 (Unix) OpenSSL/1.0.1f PHP/5.5.9 mod_perl/2.0.8-dev Perl/v5.16.3 ... which is weird, since in the folder its permission is given as drwx. I contacted the webmaster, and he said he has no clue what's going on. (Sorry, it's been a long day and I thought I'd throw in a joke; the "webmaster" is me.) Edited April 7, 2014 by stevieontario Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 7, 2014 Share Posted April 7, 2014 Go to the /home/ubuntu/myfolder directory and create an index.html and try again. Don't forget to use a tilde (~) sigh in front of your webmaster name Quote Link to comment Share on other sites More sharing options...
boompa Posted April 7, 2014 Share Posted April 7, 2014 My suggestion: Go to the /home/ubuntu/public_html directory. Type "ls -l" Copy the results here. Type "ps -ef | grep httpd" or "ps -ef | grep apache2" (whichever returns results) Copy the results here. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 7, 2014 Share Posted April 7, 2014 (edited) Go to the /home/ubuntu/public_html Yep, that was I'm thinking sorry /home/ubuntu/public_html/myfolder Edited April 7, 2014 by jazzman1 Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 7, 2014 Share Posted April 7, 2014 (edited) To solve this issue try what @trq suggested ( somehow I skipped this comment) and set permissions to ubuntu home directory to be "chmod 755 /home/ubuntu/ -R" or much better to "chmod 750 /home/ubuntu/ -R", then add apache user to be a part of ubuntu user's group. EDIT: His suggestion was to set these permissions to the sub directory, mine is to set these permissions to main user directory, otherwise the webserver won't be able to access files inside. Edited April 8, 2014 by jazzman1 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.