Jump to content

Create Username Folder In Aurigma Software


hobbiton73

Recommended Posts

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

 

I've been working on this for a couple of weeks now, and I just can't find the solution.

 

I'm using the Image Uploader software from Aurgima, and http://www.mapmyfinds.co.uk/development/index.php this is what I've managed to put together so far.

 

The problem I have is that the files are saved within a generic folder structure to be more precise:

 

'UploadedFiles' (Main folder) contaning:

  • 'files.xml'
  • saved original image
  • 'Thumbnails' (sub folder containing the saved thumbnail image)

 

What I'd like to be able to is to make the folder structure more user specific and, providing that the folder doesn't already exist I'd like to create another folder level i.e.

 

'UploadedFiles' (Main folder) contaning

  • 'Username' (subfolder containing: 'files.xml', saved original image and 'Thumbnails subfolder)

 

Please find below the script which I've put together for the 'User Input' and 'Image Upload'

 

'User Input - 'index.php'

 

<!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 
  
  $userfolder = '"$username"';
  $galleryPath = 'UploadedFiles/';
  $absGalleryPath = realpath($galleryPath) . '/';
  $dirs = array();
  if (file_exists($absGalleryPath . 'files.xml')) {
    $descriptions = new DOMDocument('1.0', 'utf-8');
    $descriptions->load($absGalleryPath . 'files.xml');
    
    for ($i = 0; $i < $descriptions->documentElement->childNodes->length; $i++) {
      $name = $descriptions->documentElement->childNodes->item($i)->getAttribute('name');
      $dir = dirname($name);
      if ($dir && $dir != '.') {
        $dirs[] = array_shift(explode('/', $dir));
      }
    }
    $dirs = array_unique($dirs);
  }
  
?>
<head>
  <title>Add New Images</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <link href="Styles/style.css" rel="stylesheet" type="text/css" />   
  <!--[if IE]>     
  <link href="../../Styles/ie.css" rel="stylesheet" type="text/css" />   <![endif]-->
  <script type="text/javascript" src="Libraries/jquery/jquery-1.4.3.min.js"></script>
  <script type="text/javascript">
  
  $(function() { 
      var uploaderID = 'Uploader1'; 
      function updateInfo() { 
          var restrictions = $au.uploader(uploaderID).restrictions(); 
          var params = { 
                    enableCmyk: restrictions.enableCmyk() && restrictions.EnableCmyk() !== "false" ? 'True' : 'True', 
                    fileMask: restrictions.fileMask() || '*.*', 
                    maxFileCount: parseInt(restrictions.maxFileCount()) || 'any', 
                    maxFileSize: parseInt(restrictions.maxFileSize()) || 'any', 
                    maxImageHeight: parseInt(restrictions.maxImageHeight()) || 'any', 
                    maxImageWidth: parseInt(restrictions.maxImageWidth()) || 'any'
          }; 
  
          var infoHtml = '<li>Allowed File Types: ${fileMask}</li>' + 
          '<li>Maximum number of files per upload: ${maxFileCount}</li>' + 
          '<li>Maximum file size: 1024KB </li>';
  
      infoHtml = infoHtml.replace(/\$\{(\w+)\}/g, function(str0, str1, offset, s) { return params[str1]; }); 
  
      $('#info').html(infoHtml); 
      } 
  
      updateInfo(); 

  }); 
    
  </script>
  
<script type="text/javascript">
  
    $(function () {
      $('input[name=folder-type]').click(function (ev) {
        $('.folder-name').attr('disabled', 'disabled').parent().addClass('disabled');
        $(this).parents('.row').removeClass('disabled').children('.folder-name').attr('disabled', '');
      });

      $('#folder-type-new').change(function() {
          $('#folderNameTextBox').select().focus();
      });

      $('#folder-type-existing').change(function() {
          $('#folderNameDropDownList').focus();
      });

      if ($('#folderNameDropDownList')[0].options.length == 0) {
        $('#folder-type-existing').attr('disabled', true);
      }

      $('#folderNameTextBox').focus();
      
    });

    function onBeforeUpload() {  
  // Get folder name 
  var folderName = $('input[name=folder-type]:checked').parents('.row').children('.folder-name').val(); 
  if (!folderName) { 
    alert('Specify folder name'); 
    return false; 
  } 
   
  // Add folder name field 
  this.metadata().addCustomField('folder', folderName); 

  count = this.files().count(); // get count of files added to upload list 
  for (i = 0; i < count; i ++){    // iterate them 
      if (this.files().get(i).description() == "") // check whether “description” is empty 
        this.files().get(i).description("No description provided");  // if so, add “No description provided” text to “description” field 
  } 
} 
  
  </script>
  <style type="text/css">
<!--
.style1 {
font-size: 14px;
margin-top: 5px;
margin-right: 110px;
}
-->
  </style>  
</head>
<body style="font-family: Calibri; color:  #505050; margin-left: 240px;">
<div align="right" class="style1"> Add Images → <a href = "imagefolders.php" /> View Uploaded Images In Folder Structure </a> </div>
<form id="addnewimages" name="addnewimages" class="page" action="index.php" method="post" enctype="application/x-www-form-urlencoded">  
  <div class="aB">
        <div class="aB-B">
          <div class="demo">
            <div class="inner"> 
              <div class="container"> 
               <fieldset class="content-block">
               <legend>Restriction settings
               <legend>username</legend><input name="username" id="username" type="text" value="IRHM73" />
		   <legend>locationid</legend><input name="locationid" id="locationid" type="text" value="1" />
               </legend> 
                    <div class="row"> 
                      <ul id='info'> 
                      </ul> 
                    </div> 
       			</fieldset> 
				<fieldset class="folder-settings content-block">
				<legend>Folder name</legend>
                  	<div class="row">
                    <label for="folder-type-new" class="caption">
                      <input type="radio" name="folder-type" id="folder-type-new" checked="checked" /> New 
                        folder </label>
                    <input type="text" id="folderNameTextBox" value="" class="folder-name"/>
                  	</div>
    				<div class="row disabled">
                    <label for="folder-type-existing" class="caption">
                      <input type="radio" name="folder-type" id="folder-type-existing" /> Existing 
                        folder </label>
                    <select id="folderNameDropDownList" class="folder-name" disabled="disabled">
                      <?php foreach ($dirs as $dir) : ?>
                        <option><?php echo htmlentities($dir, NULL, 'UTF-8'); ?></option>
                      <?php endforeach; ?>
                    </select>
      				</div>
       			 </fieldset>
                <div class="code">
                  <?php
            
                     require_once "ImageUploaderPHP/Uploader.class.php";

				// create Uploader object and specify its ID and size
				$uploader = new Uploader("Uploader1");
				$uploader->setWidth("790px");
				$uploader->setHeight("270px");


				// specify a license key
				$uploader->setLicenseKey("XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX");
				$uploader->setScriptsDirectory ('ImageUploaderPHP/Scripts');
				$uploader->getJavaControl()->setCodeBase ('ImageUploaderPHP/Scripts/ImageUploader7.jar');
				$uploader->getActiveXControl()->setCodeBase ('ImageUploaderPHP/Scripts/ImageUploader7.cab');

				// configure upload settings
				$uploader->getUploadSettings()->setActionUrl("upload.php");
			    $uploader->getUploadSettings()->setRedirectUrl("index.php");
				$uploader->getMetadata()->setAdditionalFormName("addnewimages");
				$uploader->getUploadSettings()->setFilesPerPackage(1); 	

				// setting folder pane height
				$uploader->getFolderPane()->setHeight("260");

				// setting view mode of Folder & Upload pane 
				$uploader->getFolderPane()->setViewMode('Tiles');          
				$uploader->getUploadPane()->setViewMode('Tiles'); 

				// setting of file restrictions
				$uploader->getRestrictions()->setFileMask('*.jpg;*.jpeg;*.png;*.bmp;*.gif'); 
				$uploader->getRestrictions()->setEnableCmyk(true);
				$uploader->getRestrictions()->setMaxFileCount(10);
				$uploader->getMessages()->setMaxFileCountExceeded("I'm sorry, the number of files you have selected for this upload session exceed the 10 file limit.");
				$uploader->getRestrictions()->setMaxTotalFileSize(10485760);
				$uploader->getMessages()->setMaxTotalFileSizeExceeded("I'm sorry, the number of files that you have selected for this upload session exceed the 10MB limit.");
				$uploader->getRestrictions()->setMaxFileSize(1048576);
				$uploader->getRestrictions()->setDeniedFileMask("*.exe;*.bat;*.cmd;*.wsf");

				 /* Configure converters */ 
					 //Main converter  
					 $converter1 = new Converter();  
				 $converter1->setMode('*.*=Thumbnail');  
				 $converter1->setThumbnailWidth(700);  
				 $converter1->setThumbnailHeight(700);  
				 $converter1->setThumbnailFitMode("Fit");  
				 $converter1->setThumbnailApplyCrop(true);  

				 //Converter for gallery  
				 $converter2 = new Converter();  
				 $converter2->setMode('*.*=Thumbnail');  
				 $converter2->setThumbnailWidth(180);  
				 $converter2->setThumbnailHeight(180);  
				 $converter2->setThumbnailFitMode("Fit");  
				 $converter2->setThumbnailApplyCrop(true);  
				 $uploader->setConverters(array(  
				 $converter1,  
				 $converter2 
				 ));  

						  $uploader->setConverters(array(
							$converter1,
							$converter2
						  ));

				// setting informationa and colour of files upon selection or hover over
				$uploader->getPaneItem()->setShowFileNameInThumbnailsView(TRUE);                                       
				$uploader->getDetailsViewColumns()->setInfoText('');                   
				$uploader->getDetailsViewColumns()->setDimensionsText('');

				$uploader->getClientEvents()->setBeforeUpload('onBeforeUpload');
						  
				require_once 'ImageUploaderPHP/InstallationProgress.class.php';
						  
				$ip = new InstallationProgress($uploader);
				$ip->setProgressImageUrl('Images/installation_progress.gif');
				$ip->setProgressCssClass('ip-progress');
				$ip->setInstructionsCssClass('ip-instructions');
						  
				$uploader->render();
			   ?>
                </div> 
              </div>  
          </div> 
          </div> 
    </div> 
  </div> 
</form> 
</body> 
</html>

 

Image Upload - 'upload.php'

 

<?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';

require_once 'ImageUploaderPHP/UploadHandler.class.php';

/**
* FileUploaded callback function
* @param $uploadedFile UploadedFile
*/
function onFileUploaded($uploadedFile) {

  $packageFields = $uploadedFile->getPackage()->getPackageFields();
  $username = $packageFields["username"];
  $locationid= $packageFields["locationid"];
  
  global $galleryPath;

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

  if ($uploadedFile->getPackage()->getPackageIndex() == 0 && $uploadedFile->getIndex() == 0) {
    initGallery($absGalleryPath, $absThumbnailsPath, FALSE);
  }

  $userfolder = $_POST'$userfolder'];	
  $dirName = $_POST['folder'];
  $dirName = preg_replace('/[^a-z0-9_\-\.()\[\]{}]/i', '_', $dirName);
  if (!is_dir($absGalleryPath . $dirName)) {
    mkdir($absGalleryPath . $dirName, 0777);
  }

  $path = rtrim($dirName, '/\\') . '/';

  $originalFileName = $uploadedFile->getSourceName();

  $files = $uploadedFile->getConvertedFiles();
  
  // save converter 1

  $sourceFileName = getSafeFileName($absGalleryPath, $originalFileName);
  $sourceFile = $files[0];
  /* @var $sourceFile ConvertedFile */
  if ($sourceFile) {
    $sourceFile->moveTo($absGalleryPath . $sourceFileName);
  }

  // save converter 2	
  
  $thumbnailFileName = getSafeFileName($absThumbnailsPath, $originalFileName);
  $thumbnailFile = $files[1];
  /* @var $thumbnailFile ConvertedFile */
  if ($thumbnailFile) {
    $thumbnailFile->moveTo($absThumbnailsPath . $thumbnailFileName);
  }

  //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');

  //Save file info.
  $xmlFile = $descriptions->createElement('file');
  $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());
  //Add additional fields
  $xmlFile->setAttribute('username', $userid);
  $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();
?>

 

I'm not particularly well versed in php, but I've tried to add a variable 'userfolder' to try and capture the username to create the folder, but without any success.

 

I apologise for the lengthy post, but I just wondered whether someone could perhaps take a look at this please and let me know where I'm going wrong.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.