Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
IRHM73  
#1 Posted : Wednesday, March 7, 2012 8:11:15 AM(UTC)
IRHM73

Rank: Member

Groups: Member
Joined: 2/13/2012(UTC)
Posts: 21

Thanks: 1 times
I wonder whether someone may be able to help please.

This is a segment of my 'upload.php' file capturing field values which I then process in my gallery page, also shown below:

'Upload.php'

Code:
 //Save file info.
  $xmlFile = $descriptions->createElement('file');
  $xmlFile->setAttribute('name', $_POST['folder'] . '/' . $originalFileName);
  $xmlFile->setAttribute('originalname', $originalFileName);
  $xmlFile->setAttribute('source', $path . $sourceFileName);
  $xmlFile->setAttribute('size', $uploadedFile->getSourceSize());
  //Add additional fields
[h]$xmlFile->setAttribute('description', $uploadedFile->getDescription());[/h]  
  $xmlFile->setAttribute('folder', $dirName);
  $descriptions->documentElement->appendChild($xmlFile);
  $descriptions->save($absGalleryPath . 'files.xml');

'Gallery.php'

Code:
<p><a href="<?php echo $galleryPath . 'Thumbnails/'.$fileName;?>" ><img src="<?php echo $galleryPath . 'Thumbnails/'.$fileName;?>" title="<?php echo htmlentities($xmlFile->getAttribute('originalname'));?>" alt="<?php echo htmlentities($xmlFile->getAttribute('originalname'));?>" /></a></p>
					  <p><b>Original Filename:</b> <?php echo htmlentities($xmlFile->getAttribute('originalname'));?> <br />
					  <b>User Image Description:</b> <?php echo htmlentities($xmlFile->getAttribute('description'));?> <br />
                      <b>Image Contained In Folder:</b> <?php echo htmlentities($xmlFile->getAttribute('folder'));?> <br />

What I would like to do in the scenario of there being no 'description' provided by the user I would like the 'description' field value to read 'No description provided.'

I've made several attempts at combinations of code in both scripts, the latest being:

Code:
 if(empty($xmlFile->setAttribute('description', $uploadedFile->getDescription()){
  $xmlFile->setAttribute('description', $uploadedFile->getDescription()) = 'No Description provided.';{
  else
  $xmlFile->setAttribute('description', $uploadedFile->getDescription())}; 

Unfortunately, in some respects, I don't receive any error message, but the file is not uploaded, so my code must be wrong somewhere but I'm not sure where.

I've trawled through the forum and the documentation to see if there is any guidance on how to replace blank values, but I can't find anything.

I just wondered whether someone could perhaps let me know where I'm going wrong please or point me in the direction of some documentation I've not been able to find.

Many thanks and kind regards.

Chris

Dmitry.Obukhov  
#2 Posted : Thursday, March 8, 2012 11:27:07 PM(UTC)
Dmitry.Obukhov

Rank: Advanced Member

Groups: Member
Joined: 5/29/2010(UTC)
Posts: 1,310

Thanks: 8 times
Was thanked: 111 time(s) in 111 post(s)
Hello Crhis,

You can use BeforeUpload event, where set "description" field to "No Description provided". Here is example:

Code:
function beforeUpload(){
uploader = $au.uploader('Uploader1');
count = uploader.files().count();
for (i = 0; i < count; i ++){
  if (uploader.files().get(i).description() == "")
    uploader.files().get(i).description("No Description provided");
}
}

Edited by user Thursday, March 8, 2012 11:27:39 PM(UTC)  | Reason: Not specified

Best regards,

Dmitry Obukhov

Technical Support. Aurigma, Inc.

IRHM73  
#3 Posted : Friday, March 9, 2012 6:12:58 AM(UTC)
IRHM73

Rank: Member

Groups: Member
Joined: 2/13/2012(UTC)
Posts: 21

Thanks: 1 times
Hi Dmitry, sincere thanks for this.

I'm sorry to be a little slow off the mark, but am i correct in thinking that this should go in my 'index.php' file. If so I'm having problems in implementing this piece of code because I already have another 'onBeforeUpload' event on my page.

I've added my 'index.php' script below and highlighted the appropriate lines. Could perhaps provide a little guidnace on how I can incorporate the two if this is the correct script to insert this code.

Code:
<!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"> 
<head>
<title>Add Images</title> 
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
  <link href="Styles/style.css" rel="stylesheet" type="text/css" /> 
  <script type="text/javascript" src="Libraries/jquery/jquery-1.4.3.min.js"></script> 
  <script src="Scripts/aurigma.uploader.js" type="text/javascript"></script>
 </head>
  <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();
      
    });

</script>

<script type="text/javascript">

   [h] function onBeforeUpload() { [/h]
        // 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);
    }
  
  </script>	
		
<style type="text/css">
<!--
.style1 {
	font-family: Calibri;
	font-size: 14px;
}
-->
</style>
<div class="style1">
  <div align="right">Add Images &rarr; <a href = "imagefolders.php" /> View Uploaded Images In Folder Structure </a></div>
</div>
<?php 

  $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);
  }
  
?>
<form id="addimages" name="addimages" class="page" action="index.php" method="post" enctype="application/x-www-form-urlencoded"> 
    <div class="aB"> 
    <div class="aB-B">
	  <?php if ('Uploaded files' != $current['title']) :?>
          <?php endif;?>
	          <div class="demo"> 
	               <fieldset class="content-block"> 
                  <legend>Restriction settings</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" />&nbsp;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" />&nbsp;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">
                  <p>
                    <?php
        require_once "ImageUploaderPHP/Uploader.class.php";

        // create Uploader object and specify its ID and size
        $uploader = new Uploader("Uploader1");
        $uploader->setWidth("650px");
        $uploader->setHeight("305px");
		     
        // specify a license key
        $uploader->setLicenseKey("76FF1-00071-5B800-00031-8EBBC-13B43C");
		$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");
		
		//setting folder pane height
		$uploader->getFolderPane()->setHeight("250");
		
		// 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(120);
        $converter2->setThumbnailHeight(120);
		$converter2->setThumbnailFitMode("Fit");
        $converter2->setThumbnailApplyCrop(true);
       
                  $uploader->setConverters(array(
                    $converter1,
                    $converter2
                  ));


        $uploader->getDetailsViewColumns()->setDimensionsText('');
                  
       [h] $uploader->getClientEvents()->setBeforeUpload('onBeforeUpload');[/h]
                  
        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();
       ?>

</p>
</div>
        </div> 
  </div> 
    </div>
</form> 
</body> 
</html>

Many thanks and kind regards

Chris

Dmitry.Obukhov  
#4 Posted : Friday, March 9, 2012 8:00:43 PM(UTC)
Dmitry.Obukhov

Rank: Advanced Member

Groups: Member
Joined: 5/29/2010(UTC)
Posts: 1,310

Thanks: 8 times
Was thanked: 111 time(s) in 111 post(s)
Hello Chris :)

Sorry for this misunderstanding.

Yes, you need to add BeforeUpload event which I showed to index.php file. If you have this one already, it is okay :) You just need to add my code after yours. Please see this code snippet:

Code:

<script type="text/javascript">
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);
  
  //Dmitry’s code
  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>    

If something is not clear, please let me know, Chris.

Best regards,

Dmitry Obukhov

Technical Support. Aurigma, Inc.

IRHM73  
#5 Posted : Saturday, March 10, 2012 7:25:36 AM(UTC)
IRHM73

Rank: Member

Groups: Member
Joined: 2/13/2012(UTC)
Posts: 21

Thanks: 1 times
Hi Dmitry, there is no need to apologise. It was my lack of PHP knowledge that let me down and not you :)

The code works great.

Thank you so much, once again.

Kind regards

Chris

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.