Use Field Values For Filepath
<p>I wonder whether someone may be able to help me please.</p>

<p>I'm trying to load an xml file with the following filepath:</p>

<pre><code>/UploadedFiles/username/location/files.xml
</code></pre>

<p>What I've been trying to do for some time, is to use the values of two forms fields, 'username' and 'location' and incorporate them into the filepath, but I just can't seem to get this right.</p>

<p>I just wondered whether someone could someone perhaps tell me how I take these values and use them in the filepath.</p>

<p>Many thanks</p>

<p><strong>POST AMENDMENT</strong></p>

<p>I thought I could solve my issues by simply changing the file path, hence my original post, but I fear my lack of PHP knowledge as let me down and I suspect the issues I have are deeper within my code. </p>

<p>Please find below more detail.</p>

<p>The script below shows how I initially save the images.</p>

<p><strong>'upload.php'</strong></p>

<pre><code>&lt;?php
require_once 'Includes/gallery_helper.php'; 
require_once 'ImageUploaderPHP/UploadHandler.class.php'; 
$galleryPath = 'UploadedFiles/'; 

function onFileUploaded($uploadedFile) { 
  global $galleryPath; 

  $packageFields = $uploadedFile-&gt;getPackage()-&gt;getPackageFields(); 
  $username=$packageFields["username"]; 
  $locationid=$packageFields["locationid"]; 
  $username = preg_replace('/[^a-z0-9_\-\.()\[\]{}]/i', '_', $_POST['username']); 
  $location = preg_replace('/[^a-z0-9_\-\.()\[\]{}]/i', '_', $_POST['locationid']); 
  $dirName = preg_replace('/[^a-z0-9_\-\.()\[\]{}]/i', '_', $_POST['folder']); 

  $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR . $username . DIRECTORY_SEPARATOR . $location . DIRECTORY_SEPARATOR; 
  $absThumbnailsPath = $absGalleryPath . 'Thumbnails' . DIRECTORY_SEPARATOR; 


  if (!is_dir($absGalleryPath)) mkdir($absGalleryPath, 0777, true); 
  chmod($absGalleryPath, 0777); 
  if (!is_dir($absGalleryPath . $dirName)) mkdir($absGalleryPath . $dirName, 0777, true); 
  chmod($absGalleryPath . $dirName, 0777); 

  if ($uploadedFile-&gt;getPackage()-&gt;getPackageIndex() == 0 &amp;&amp; $uploadedFile-&gt;getIndex() == 0) 
    initGallery($absGalleryPath, $absThumbnailsPath, FALSE); 

  $originalFileName = $uploadedFile-&gt;getSourceName(); 
  $files = $uploadedFile-&gt;getConvertedFiles(); 
  $sourceFileName = getSafeFileName($absGalleryPath, $originalFileName); 
  $sourceFile = $files[0]; 

  if ($sourceFile) $sourceFile-&gt;moveTo($absGalleryPath . $sourceFileName); 
  $thumbnailFileName = getSafeFileName($absThumbnailsPath, $originalFileName); 
  $thumbnailFile = $files[1]; 
  if ($thumbnailFile) $thumbnailFile-&gt;moveTo($absThumbnailsPath . $thumbnailFileName); 

  $descriptions = new DOMDocument('1.0', 'utf-8'); 
  $descriptions-&gt;load($absGalleryPath . 'files.xml'); 

  $xmlFile = $descriptions-&gt;createElement('file'); 
  // &lt;-- please check the following line 
  $xmlFile-&gt;setAttribute('name', $_POST['folder'] . '/' . $originalFileName); 
  $xmlFile-&gt;setAttribute('source', $sourceFileName); 
  $xmlFile-&gt;setAttribute('size', $uploadedFile-&gt;getSourceSize()); 
  $xmlFile-&gt;setAttribute('originalname', $originalFileName); 
  $xmlFile-&gt;setAttribute('thumbnail', $thumbnailFileName); 
  $xmlFile-&gt;setAttribute('description', $uploadedFile-&gt;getDescription()); 
  $xmlFile-&gt;setAttribute('username', $username); 
  $xmlFile-&gt;setAttribute('locationid', $locationid); 
  $xmlFile-&gt;setAttribute('folder', $dirName); 


  $descriptions-&gt;documentElement-&gt;appendChild($xmlFile); 
  $descriptions-&gt;save($absGalleryPath . 'files.xml'); 
} 

$uh = new UploadHandler(); 
$uh-&gt;setFileUploadedCallback('onFileUploaded'); 
$uh-&gt;processRequest(); 
?&gt;
</code></pre>

<p>This script produces the following file structure:</p>

<p>UploadedFiles (Pre-existing folder)</p>

<ul>
<li>'username' (Subfolder containing 'location' folder)</li>
<li>'location' (Subfolder containing original image, 'files.xml' and 'Thumbnails' folder)</li>
<li>'Thumbnails' (Subfolder containing thumbnail of original image)</li>
</ul>

<p><strong>NB.</strong> The 'username' and 'location folder names are derived from the current user and location values.</p>

<p>I then come onto my issue with the creation of the image gallery.</p>

<p>The code below is my initial 'gallery.php' script. I need to change the top PHP section of the script to match the new folder structure i.e. <code>UploadedFiles/'username'/'location'/Thumbnails</code> and <code>UploadedFiles/'username'/'location'.files.xml</code></p>

<p>'gallery.php'</p>

<pre><code>&lt;?php 

  $galleryPath = 'UploadedFiles/'; 

  $thumbnailsPath = $galleryPath . 'Thumbnails/'; 

  $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR; 

  $descriptions = new DOMDocument('1.0'); 
  $descriptions-&gt;load($absGalleryPath . 'files.xml'); 
?&gt;
&lt;head&gt; 
  &lt;title&gt;Gallery&lt;/title&gt; 
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt; 
  &lt;link href="Libraries/fancybox/jquery.fancybox-1.3.1.css" rel="stylesheet" type="text/css" /&gt; 
  &lt;link href="Styles/style.css" rel="stylesheet" type="text/css" /&gt; 
  &lt;!--[if IE]&gt;   
  &lt;link href="Styles/ie.css" rel="stylesheet" type="text/css" /&gt; 
  &lt;![endif]--&gt;
  &lt;script src="Libraries/jquery/jquery-1.4.3.min.js" type="text/javascript"&gt;&lt;/script&gt; 
  &lt;script src="Libraries/fancybox/jquery.fancybox-1.3.1.pack.js" type="text/javascript"&gt;&lt;/script&gt; 
  &lt;script type="text/javascript"&gt; 

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

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

<p>I admit to being at a real loss at how to solve this, I don't whether it's my 'gallery.php' script that needs to change or my 'upload.php'</p>

<p>Any help would be so gratefully received.</p>

<p>Kind regards</p>
