Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7673997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:38:26+00:00 2026-05-31T16:38:26+00:00

I wonder whether someone can help me please. I’m using the following script to

  • 0

I wonder whether someone can help me please.

I’m using the following script to load images from an XML file into a web 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. 
  //Do not forget about the slash in the end of the folder name. 
  $galleryPath = 'UploadedFiles/'; 

  $thumbnailsPath = $galleryPath . 'Thumbnails/'; 

  $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR; 

  $descriptions = new DOMDocument('1.0'); 
  $descriptions->load($absGalleryPath . 'files.xml'); 
?>
<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;?>
          <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>

Amended Code With XPath – NB Not A Working Solution

<!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. 
  //Do not forget about the slash in the end of the folder name. 
  $galleryPath = 'UploadedFiles/'; 

  $thumbnailsPath = $galleryPath . 'Thumbnails/'; 

  $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR; 

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

   $xpath = new DOMXPATH($descriptions);
?>
<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;?>
          <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++) : 
                          $name = $xpath->query("files/file[@userid=" . userid . " and @locationid=" . locationid . "]/@originalname");   
                          $description = $xpath->query("files/file[@userid=" . userid . " and @locationid=" . locationid . "]/@description");   
                          $folder = $xpath->query("files/file[@userid=" . userid . " and @locationid=" . locationid . "]/@folder");   
                          $source = $xpath->query("files/file[@userid=" . userid . " and @locationid=" . locationid . "]/@source");         
                          $thumbnail = $xpath->query("files/file[@userid=" . userid . " and @locationid=" . locationid . "]/@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 $description;?> <br /> 
                            <b>Image contained in folder:</b> <?php echo $folder;?> </span><br />   

                          </li> 
                        </p> 
            <?php endfor; ?> 
</ul> 
                </div> 
              </div> 
            </div> 
          </div> 
        </div> 
      </div> 
    </div> 
    </div> 
        <div class="aB-a">        </div> 
      </div> 
    </div> 
  </div> 
  </form> 
</body> 
</html>

and this is the XML file which is loaded into the page:

  <?xml version="1.0" encoding="utf-8" ?> 
- <files>
  <file name="Test 1/_47061196_greatbritainjpg.jpg" source="_47061196_greatbritainjpg.jpg" size="227505" originalname="_47061196_greatbritainjpg.jpg" thumbnail="_47061196_greatbritainjpg.jpg" description="No description provided" userid="1" locationid="1" folder="Test_1" />  
  <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" /> 
  <file name="Test 1/stags-snow_1544533c.jpg" source="stags-snow_1544533c.jpg" size="21341" originalname="stags-snow_1544533c.jpg" thumbnail="stags-snow_1544533c.jpg" description="No description provided" userid="1" locationid="1" folder="Test_1" /> 
  </files>

What I would like to do is to make the images loaded user specific, so for example ‘userid’ of value ‘1’ at ‘locationid’ value ‘1’ can only view those images with the matching values in the XML file.

I know from the tutorials and articles I’ve read that an ‘Xpath’ statement is able to do this. However there appears to be many different ways to do this, and having very, very, little of XML I’m really not sure where to start.

I just wondered whether someone could perhaps offer me some help please to help me to be able to achieve this.

Kind regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:38:27+00:00Added an answer on May 31, 2026 at 4:38 pm

    No problem!

    For your xpath statement, I’m assuming you would want to return the filename of whichever xml node that contains the userid and locationid you need.

    So you would first start at the root node , then check which file has this criteria:

    locationid and userid are both attributes of , so you need to use the @ symbol when referencing them in xpath.

    $xpath = new DOMXPATH($descriptions) ; 
    $result = $xpath->query("files/file[@userid=" . userid . " and @locationid=" . locationid . "]/@name");
    

    This might look a little confusing since your attribute names are the same as the input names, but the variables in the “. .” are referring to the block:

    <input name="userid" type="text" id="userid" value="1" />
    <input name="locationid" type="text" id="locationid" value="1" />
    

    So this would give you the name of the file for that user, which you could apply to your $source tag. Just repeat the given xpath and append /@description or /@thumbnail in place of name to get the other values.

    Hope this helps, let me know if I need to clarify anything!

    Try this:

    (not sure where your input form went in the original code, but if you’re still using it:)

    <ul class="gallery-image-list"> 
                      <?php for ($i = 0; $i < $descriptions->documentElement->childNodes->length; $i++) :
                              $name = $xpath->query("files/file[@userid=" . userid . " and @locationid=" . locationid . "]/@originalname");  
                              $description = $xpath->query("files/file[@userid=" . userid . " and @locationid=" . locationid . "]/@description");  
                              $folder = $xpath->query("files/file[@userid=" . userid . " and @locationid=" . locationid . "]/@folder");  
                              $source = $xpath->query("files/file[@userid=" . userid . " and @locationid=" . locationid . "]/@source");        
                              $thumbnail = $xpath->query("files/file[@userid=" . userid . " and @locationid=" . locationid . "]/@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 $description;?> <br />
                                <b>Image contained in folder:</b> <?php echo $folder;?> </span><br />  
    
                              </li>
                            </p>
                <?php endfor; ?>
    </ul>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder whether someone can help me please. I have the following xml file
I wonder whether someone can help me please. I'm using the following script to
I wonder whether someone can help me please. I've put together the script below
I wonder whether someone can help please. I'm trying to put together a script
I wonder whether someone can help me please. I've put together the following which
I wonder whether someone can help me please. I have the following three tables:
wonder whether someone can help me with the following one... I have a struct
I wonder whether someone can help me please. I've created this form which allows
I wonder whether someone can help me please. I'm trying to implement the mysql_insert_id()
I wonder whether someone could help me please, From a tutorial I found online

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.