Cannot Load XML File and Thumbnails
Results 1 to 5 of 5

Thread: Cannot Load XML File and Thumbnails

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    14

    Cannot Load XML File and Thumbnails

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

    Using Image Uploader From Aurigma, I've put together the following code which allows users to upload images for locations they have visited.

    'upload.php'
    Code:
    <?php
    require_once 'Includes/gallery_helper.php'; 
    require_once 'ImageUploaderPHP/UploadHandler.class.php'; 
    $galleryPath = 'UploadedFiles/'; 
     
    function onFileUploaded($uploadedFile) { 
      global $galleryPath; 
     
      $packageFields = $uploadedFile->getPackage()->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->getPackage()->getPackageIndex() == 0 && $uploadedFile->getIndex() == 0) 
        initGallery($absGalleryPath, $absThumbnailsPath, FALSE); 
     
      $originalFileName = $uploadedFile->getSourceName(); 
      $files = $uploadedFile->getConvertedFiles(); 
      $sourceFileName = getSafeFileName($absGalleryPath, $originalFileName); 
      $sourceFile = $files[0]; 
     
      if ($sourceFile) $sourceFile->moveTo($absGalleryPath . $sourceFileName); 
      $thumbnailFileName = getSafeFileName($absThumbnailsPath, $originalFileName); 
      $thumbnailFile = $files[1]; 
      if ($thumbnailFile) $thumbnailFile->moveTo($absThumbnailsPath . $thumbnailFileName); 
      
      $descriptions = new DOMDocument('1.0', 'utf-8'); 
      $descriptions->load($absGalleryPath . 'files.xml'); 
      
      $xmlFile = $descriptions->createElement('file'); 
      // <-- please check the following line 
      $xmlFile->setAttribute('name', $_POST['folder'] . '/' . $originalFileName); 
      $xmlFile->setAttribute('source', $sourceFileName); 
      $xmlFile->setAttribute('size', $uploadedFile->getSourceSize()); 
      $xmlFile->setAttribute('originalname', $originalFileName); 
      $xmlFile->setAttribute('thumbnail', $thumbnailFileName); 
      $xmlFile->setAttribute('description', $uploadedFile->getDescription()); 
      $xmlFile->setAttribute('username', $username); 
      $xmlFile->setAttribute('locationid', $locationid); 
      $xmlFile->setAttribute('folder', $dirName); 
     
    
      $descriptions->documentElement->appendChild($xmlFile); 
      $descriptions->save($absGalleryPath . 'files.xml'); 
    } 
     
    $uh = new UploadHandler(); 
    $uh->setFileUploadedCallback('onFileUploaded'); 
    $uh->processRequest(); 
    ?>
    This code creates the following folder and file structure:

    UploadedFiles (Top level pre existing folder containing all files and folders)
    • username (Subfolder created using value of current user, containing 'location' folder)
    • location (Subfolder created using value of current location, containing 'Thumbnails' folder, original image and 'files.xml')
    • Thumbnails (Subfolder created containing thumbnails of original images)


    The problem I'm having, and have have had for the last few weeks, is in trying to retrieve these images to create a gallery.

    The code below, is an extract of my 'gallery.php' script that I initally started with. These lines specifically handle the loading of the 'thumbnail' image and 'files.xml'.

    Code:
    <?php 
       
      $galleryPath = 'UploadedFiles/'; 
        
      $thumbnailsPath = $galleryPath . 'Thumbnails/'; 
        
      $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR; 
        
      $descriptions = new DOMDocument('1.0'); 
      $descriptions->load($absGalleryPath . 'files.xml'); 
    ?>
    I need to change these lines of code to match my new folder structure and incorporate the 'username' and 'location' folder levels, but because the values change depending on the current user and location I've been unable to get this to work.

    I've tried all sorts of permuations of code, all without success e.g.

    Code:
    <?php 
       
      $galleryPath = = "/UploadedFiles/".$username."/".$location."/files.xml"; 
        
      $thumbnailsPath = $galleryPath . 'Thumbnails/'; 
         
      $descriptions = new DOMDocument('1.0'); 
      $descriptions->load($galleryPath . 'files.xml'); 
    ?>
    Code:
    <?php 
       
      $galleryPath = = "/UploadedFiles/{$_REQUEST['username']}/{$_REQUEST['location']}/files.xml" 
        
      $thumbnailsPath = $galleryPath . 'Thumbnails/'; 
        
    ?>
    Code:
    <?php 
       
      $galleryPath = 'UploadedFiles/'; 
        
      $thumbnailsPath = $galleryPath . 'Thumbnails/'; 
        
      $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR . $usernamefolder . DIRECTORY_SEPARATOR . $locationfolder . DIRECTORY_SEPARATOR;  
        
      $descriptions = new DOMDocument('1.0'); 
      $descriptions->load($absGalleryPath . 'files.xml'); 
    ?>
    I'm not even sure whether the probem lies within my 'gallery.php or 'upload.php script.

    But I am at a loss about what to do next, I would be so grateful if someone could take a look at this and let me know where I'm going wrong.

    Many thanks and regards

  2. #2
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,889
    Assuming $username and $location are suitably defined, the first one looks more or less right:
    PHP Code:
      $galleryPath = = "/UploadedFiles/".$username."/".$location."/files.xml"
    Except that the leading "/" is probably not supposed to be there (nor the extra '=' of course). Have you considered building the path up in the same way that you do when creating the directories in the first place? I.e.,
    PHP Code:
      $absGalleryPath realpath($galleryPath) . DIRECTORY_SEPARATOR $username DIRECTORY_SEPARATOR $location DIRECTORY_SEPARATOR
      
    $absThumbnailsPath $absGalleryPath 'Thumbnails' DIRECTORY_SEPARATOR
    And similar?
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    14
    Hi, many thanks for taking the time to reply to my post.

    Yes I had tried to duplicate how the files were initially created with 'upload.php' but when I use this I receive the following error:

    Warning: DOMDocument::load() [domdocument.load]: I/O warning : failed to load external entity "/homepages/2/d333603417/htdocs/development/UploadedFiles/files.xml" in /homepages/2/d333603417/htdocs/development/gallery.php on line 16
    I do think that you hit the 'nail on the head' though. The problem I have is defining the 'username' and 'location' folder names because they are dynamic values.

    These values are part of my form via two text fields, and I've tried so many ways to pass this value as a variable to the file path, unforunately without success.

    Kind regards

  4. #4
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,889
    So where is this "files.xml" of which you speak? According to your error message, on line 16 of gallery.php (which you haven't shown), you're trying to load it from ...UploadedFiles/files.xml, which is inconsistent with everything else you've posted (which would imply that there is supposed to be some username and location between UploadedFiles and files.xml.) There aren't even the extra directory separators that would be there if username and location were being inserted but were empty strings.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  5. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    14
    Hi, many thanks for your continued help with this.

    The
    'files.xml'
    file can be found in the following path:

    UploadedFiles/username/location/files.xml.
    Sincere apologies for not highlighting line 16. it is this line in my code:

    $descriptions->load($absGalleryPath . 'files.xml');
    You are also correct, as I also highlighted in my original post, that between 'UploadedFiles' and 'files.xml' the 'username' and 'location' folders need to be added.

    This highlights the problem I'm having. I don't know how to incorporate the string for the 'username' and 'location' folders in my filepath and for these values to chnage to match the current user and location i.e. so that the only the current user and location images are retrieved.

    I hope this helps

    Kind regards

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •