syngod Posted August 11, 2013 Share Posted August 11, 2013 hey guys, having issues trying to get xml to load a file that has date as it's file name. I have a script that creates an xml. <?php $companyName = ($_GET['VcomName']); $visitDate = ($_GET['Vdate']); $visitors = ($_GET['Vname']); //$VcomName = 'test'; $vdoc = new DOMDocument('1.0'); $vdoc->formatOutPut = true; $root = $vdoc->createElement('VisitorList'); $root = $vdoc->appendChild($root); $company = $vdoc->createElement('CompanyName'); $company = $root->appendChild($company); $ctext = $vdoc->createTextNode($companyName); $ctext = $company->appendChild($ctext); $visitor = $vdoc->createElement('Visitors'); $visitor = $root->appendChild($visitor); $vtext = $vdoc->createTextNode($visitors); $vtext = $visitor->appendChild($vtext); $ddate = $vdoc->createElement('VisitDate'); $ddate = $root->appendChild($ddate); $dtext = $vdoc->createTextNode($visitDate); $dtext = $ddate->appendChild($dtext); echo $vdoc->save($visitDate. ".xml") . "\n"; ?> It creates the file with the date submited in a form for a visitor board. Im trying to open the file so that i can print out the visitor names and the company that is visiting. <?php libxml_use_internal_errors(true); $fileD=date('Y-m-d'); echo "$fileD \n"; $file = "/inc/$fileD.xml"; include "/inc/2013-08-11.xml"; $file = preg_replace('/[\s]+/',' ',$file); if(file_exists($file)) { $fxml = simplexml_load_file($file); print_r($fxml); } else { exit("The file $file Does not exist \n"); } ?> In this i have done some testing ... the include will work but the simplexml fails to find the file. All it gives me is the exit printout on the screen. Im not sure why this is not working. there are no errors besides unable to find the file. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted August 11, 2013 Share Posted August 11, 2013 what exactly does $_GET['Vdate'] contain when the file is created? does it have any leading/trailing spaces or new-line characters? Quote Link to comment Share on other sites More sharing options...
syngod Posted August 11, 2013 Author Share Posted August 11, 2013 It actually comes from an HTML5 from that i have. <form action="inc/xml_create.php" autocomplete="off"> <label for="date" tabindex="1">Date of Visit</label> <input type="date" name="Vdate" id="date" required> <label for="company" tabindex="2">Company Name</label> <input type="text" name="VcomName" id="company"> <label for="visitor" tabindex="3">Visitor name(s)</label> <textarea name="Vname" id="visitor"></textarea> <input type="submit" value="Submit Form"> </form> Im using the HTML5 input date type. So im not sure.. i tried to elemenate any spaces with the preg_replace in the code above. Not sure about new line charecters. Quote Link to comment Share on other sites More sharing options...
syngod Posted August 11, 2013 Author Share Posted August 11, 2013 Here is the output of the file to view the XML file incase it might help. 2013-08-11 ranoshofftesting2013-08-13 The file /inc/2013-08-11.xml Does not exist Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted August 11, 2013 Solution Share Posted August 11, 2013 the reason for this is the path you are specifying. the leading / is forming an absolute file system path, which is not where your file is actually at. however, if the include() statement doesn't find the file where you specify, it will "finally check in the calling script's own directory and the current working directory before failing.", apparently even for absolute paths, which the documentation hints it won't do. so, the include() statement is finding the file, but your other statements won't. since it appears that your form and your second piece of code are both in the parent folder that contains the inc/ folder, just remove the leading / from the file path, both in the $file variable and in the include statement, to form the correct path to where the file is at. also, your preg_replace() is trying to convert multiple spaces to a single space, but for at least the posted code, there are no spaces at all since the date is being directly built. if the date was from external data and it could contain spaces..., you would want to remove all of them, not convert multiple ones to a single one. Quote Link to comment Share on other sites More sharing options...
syngod Posted August 11, 2013 Author Share Posted August 11, 2013 (edited) Well thank you i was unaware that smiplexml needed relative paths. Thanks. And i guess i need to work on my regular expression as well. Edited August 11, 2013 by syngod Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted August 12, 2013 Share Posted August 12, 2013 the problem isn't that smiplexml needs a relative path. an absolute file system path would work, but the absolute path you supplied is not correct. the leading / refers to the root of the current disk. that's not where your path/file is at. it just turns out that include() went ahead and found the file relative to the calling script's own directory and the current working directory when it did not find it at that absolute path. 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.