<?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/';
require_once '../Includes/gallery_helper.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR;
$absThumbnailsPath = $absGalleryPath . 'Thumbnails' . DIRECTORY_SEPARATOR;
// Clear previously uploaded files
if ($_POST['PackageIndex'] == 0) {
initGallery($absGalleryPath, $absThumbnailsPath);
}
//Load XML file which will keep information about files (image dimensions, description, etc).
//XML is used solely for brevity. In real-life application most likely you will use database instead.
$descriptions = new DOMDocument('1.0', 'utf-8');
$descriptions->load($absGalleryPath . 'files.xml');
//Get total number of uploaded files (all files are uploaded in a single package).
$fileCount = $_POST["PackageFileCount"];
//Iterate through uploaded data and save the original file, thumbnail, and description.
for ($i = 0; $i < $fileCount; $i++) {
$originalFileName = rawurlencode($_REQUEST['SourceName_' . $i]);
//save source file
$sourceFileName = getSafeFileName($absGalleryPath, $originalFileName);
if (isset($_FILES['File0_' . $i])) {
move_uploaded_file($_FILES['File0_' . $i]['tmp_name'], $absGalleryPath . $sourceFileName);
}
//Save file info.
$xmlFile = $descriptions->createElement('file');
$xmlFile->setAttribute('name', $originalFileName);
$xmlFile->setAttribute('source', $sourceFileName);
$xmlFile->setAttribute('thumbnail', $thumbnailFileName);
$descriptions->documentElement->appendChild($xmlFile);
}
$descriptions->save($absGalleryPath . 'files.xml');
}