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'
<?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'.
<?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.
<?php
$galleryPath = = "/UploadedFiles/".$username."/".$location."/files.xml";
$thumbnailsPath = $galleryPath . 'Thumbnails/';
$descriptions = new DOMDocument('1.0');
$descriptions->load($galleryPath . 'files.xml');
?>
<?php
$galleryPath = = "/UploadedFiles/{$_REQUEST['username']}/{$_REQUEST['location']}/files.xml"
$thumbnailsPath = $galleryPath . 'Thumbnails/';
?>
<?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