0

I wonder whether someone may be able to help me please.

I'm using the script below to create a 'gallery' page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<?php 

  //This variable specifies relative path to the folder, where the gallery with uploaded files is located. 

  $galleryPath = 'UploadedFiles/'; 

  $thumbnailsPath = $galleryPath . 'Thumbnails/'; 

  $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR; 

  $descriptions = new DOMDocument('1.0'); 
  $descriptions->load($absGalleryPath . 'files.xml'); 

  path="files[userid=1]/originalname/folder/description/source/thumbnail";
// code for IE
if (window.ActiveXObject)
{
var nodes=xml.selectNodes(path);

for (i=0;i<nodes.length;i++)
  {
  document.write(nodes[i].childNodes[0].nodeValue);
  }
}

?>
<head> 
  <title>Gallery</title> 
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
  <link href="Libraries/fancybox/jquery.fancybox-1.3.1.css" rel="stylesheet" type="text/css" /> 
  <link href="Styles/style.css" rel="stylesheet" type="text/css" /> 
  <!--[if IE]>   
  <link href="Styles/ie.css" rel="stylesheet" type="text/css" /> 
  <![endif]-->
  <script src="Libraries/jquery/jquery-1.4.3.min.js" type="text/javascript"></script> 
  <script src="Libraries/fancybox/jquery.fancybox-1.3.1.pack.js" type="text/javascript"></script> 
  <script type="text/javascript"> 

  $(function() { $('a.fancybox').fancybox(); }); 

  </script> 
  <style type="text/css">
<!--
.style1 {
    font-size: 14px;
    margin-right: 110px;
}
.style4 {font-size: 12px}
-->
  </style>
</head>
<body style="font-family: Calibri; color:  #505050; font-size: 9px; border-bottom-width: thin; margin-top: 5px; margin-left: -475px; margin-right: 1px; margin-bottom: -10px;">
<div align="right" class="style1"> <a href = "imagefolders.php" /> View Uploaded Images In Folder Structure <a/> &larr; View All Uploaded Images </div>
  <form id="gallery" class="page"> 
  <div id="container"> 
    <div id="center"> 
      <div class="aB"> 
        <div class="aB-B"> 
          <?php if ('Uploaded files' != $current['title']) :?>
          <?php endif;?>
          <label>
          <input name="userid" type="text" id="userid" value="1" />
          <input name="locationid" type="text" id="locationid" value="1" />
          </label>
          <div class="demo"> 
            <div class="inner"> 
              <div class="container"> 
                <div class="gallery"> 
                  <ul class="gallery-image-list"> 
                  <?php for ($i = 0; $i < $descriptions->documentElement->childNodes->length; $i++) : 
                          $xmlFile = $descriptions->documentElement->childNodes->item($i); 
                          $name = htmlentities($xmlFile->getAttribute('originalname'), ENT_COMPAT, 'UTF-8'); 
                          $description = htmlentities($xmlFile->getAttribute('description'), ENT_COMPAT, 'UTF-8'); 
                          $folder = htmlentities($xmlFile->getAttribute('folder'), ENT_COMPAT, 'UTF-8'); 
                          $source = $galleryPath . rawurlencode($xmlFile->getAttribute('source')); 
                          $thumbnail = $thumbnailsPath . rawurlencode($xmlFile->getAttribute('thumbnail')); 
                  ?>
                    <li class="item"> 
                      <a class="fancybox" target="_blank" rel="original" href="<?php echo $source; ?>"><img class="preview" 
                        alt="<?php echo $name; ?>"  src="<?php echo $thumbnail; ?>" /></a>                      </li>
                        <li class="item"></li>
                        <p><span class="style4"><b>Image Description:</b> <?php echo htmlentities($xmlFile->getAttribute('description'));?> <br />
                            <b>Image contained in folder:</b> <?php echo htmlentities($xmlFile->getAttribute('folder'));?> </span><br />  
                          <?php endfor; ?>
                          </li>
                    </p>
                  </ul>
                </div> 
              </div> 
            </div> 
          </div> 
        </div> 
      </div> 
    </div> 
    </div> 
        <div class="aB-a">        </div> 
      </div> 
    </div> 
  </div> 
  </form> 
</body> 
</html>

The data for this page comes from the file, 'files.xml', an extract of which can be found below.

<?xml version="1.0" encoding="utf-8" ?> 
- <files>
  <file name="Test 1/article-0-07D01B74000005DC-138_468x617.jpg" source="article-0-07D01B74000005DC-138_468x617.jpg" size="143110" originalname="article-0-07D01B74000005DC-138_468x617.jpg" thumbnail="article-0-07D01B74000005DC-138_468x617.jpg" description="No description provided" userid="1" locationid="1" folder="Test_1" /> 
  </files>

What I wanted to do is filter the records returned, to be more specific by 'userid' and 'locationid' and for testing purposes these had the value of '1'.

I'd received some useful guidance from this site at XML 'Select Where' Statement, and from the subsequent 'XPath' tutorials I've read I put together what I thought would be the correct xpath code to use which is at the top of my 'gallery' page script.

However, when I've tried to run this I recieve the following error:

Parse error: syntax error, unexpected '=' in /homepages/2/d333603417/htdocs/development/gallery.php on line 16

It's clear that the problem is with the 'equals', but when I've gone back to the tutorials, this appears to be the correct syntax to use.

I just wondered whether someone could perhaps have a look at this please and let me know where I've gone wrong.

Many thanks

Amended Xpath Code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<?php 

  $galleryPath = 'UploadedFiles/'; 

  $thumbnailsPath = $galleryPath . 'Thumbnails/'; 

  $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR; 

  $descriptions = new DOMDocument('1.0'); 
  $descriptions->load($absGalleryPath . 'files.xml'); 

  /files/file[@userid="1" and @locationid="1"];


?>
Community
  • 1
  • 1
IRHM
  • 1,326
  • 11
  • 77
  • 130

1 Answers1

1

Line 16 is

path="files[userid=1]/originalname/folder/description/source/thumbnail";

If this is PHP code the you need $ before path.

The code below that line seems to be Javascript. So you should probably pass the PHP variable $path into the Javascript with syntax like:

var path = "<?=$path ?>";

HTH,

  • Eli
Sirko
  • 72,589
  • 19
  • 149
  • 183
Eli Rosencruft
  • 7,232
  • 1
  • 19
  • 17
  • Hi, many thanks for this. I must admit to being quite a bit out of my depth here, because I'm not sure what I need to include in addition to the script I have already. The code that I had originally included came from a tutorial I had been working through.I've just tried using the line `$path="files[userid=1]/originalname/folder/description/source/thumbnail";` by itslef but unfortunately it still retrieves all the records. Kind regards – IRHM Mar 17 '12 at 18:13
  • Not clear to me how you made the query "files[userid=1]/originalname/folder/description/source/thumbnail". – Eli Rosencruft Mar 17 '12 at 23:08
  • From the XML, it looks like "originalname", "folder", "description", etc are attributes of "file", in which case the query should probably be something like "/files/file[@userid="1"]" for just the userid 1. If you want to search by more attributes, then "/files/file[@userid="1" and @originalname="somename"]", etc. – Eli Rosencruft Mar 17 '12 at 23:16
  • Hi, many thanks for taking the time to reply and help me. I got the original xpath from reading tutorials, which clearly I didn't understand. I've used your suggested code in my script and I've added this to my original post to show you what it now looks like, but unfortunately I receive the following error:`Parse error: syntax error, unexpected '/' in /homepages/2/d333603417/htdocs/development/gallery.php on line 16` with line 16 being the xpath line. Could you perhaps tell me please where I've gone wrong. Kind regards – IRHM Mar 18 '12 at 13:37