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

Notification

Icon
Error

Options
Go to last post Go to first unread
bgordon  
#1 Posted : Wednesday, November 9, 2011 8:20:56 PM(UTC)
bgordon

Rank: Newbie

Groups: Member
Joined: 9/28/2011(UTC)
Posts: 5

In the upload.php demo (the one that writes to the XML file below)... $uploadedFile->getSourceHeight() gets the original height. What syntax do I use to get the modified height of the two thumb variations I am uploading?

I see a method called getHeight() am not sure how to call it, since $uploadedFile->getHeight(); is not right. See my note in the code below (XML write section)

Code:

<?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) {
  global $galleryPath;
 
  $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR;
  $absThumbnailsPath = $absGalleryPath . 'Thumbnails' . DIRECTORY_SEPARATOR;
 
  if ($uploadedFile->getPackage()->getPackageIndex() == 0 && $uploadedFile->getIndex() == 0) {
    initGallery($absGalleryPath, $absThumbnailsPath);
  }
 
  $originalFileName = $uploadedFile->getSourceName();
 
  $files = $uploadedFile->getConvertedFiles();
 
  // Save source file
  $sourceFile = $files[0];
  /* @var $sourceFile ConvertedFile */
  if ($sourceFile) {
    $sourceFileName = getSafeFileName($absGalleryPath, $originalFileName);
    $sourceFile->moveTo($absGalleryPath . $sourceFileName);
  }
 
  //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', $originalFileName);
  $xmlFile->setAttribute('source', $sourceFileName);
  $xmlFile->setAttribute('description', $uploadedFile->getDescription());
  $xmlFile->setAttribute('originalHeight', $uploadedFile->getSourceHeight());
  $xmlFile->setAttribute('originalWidth', $uploadedFile->getSourceWidth());

// HOW DO I MAKE THIS VALID...

// First Image Converter
  $xmlFile->setAttribute('new0Height', $uploadedFile->getHeight()); <----- wrong
  $xmlFile->setAttribute('new0Width', $uploadedFile->getWidth()); <----- wrong

// Second Image Converter
  $xmlFile->setAttribute('new1Height', $uploadedFile->getHeight()); <----- wrong
  $xmlFile->setAttribute('new1Width', $uploadedFile->getWidth()); <----- wrong

// How do i reference the converted height/width for each variation (I upload two) from the $files variable?

  $descriptions->documentElement->appendChild($xmlFile);
  $descriptions->save($absGalleryPath . 'files.xml');
}
 
$uh = new UploadHandler();
$uh->setFileUploadedCallback('onFileUploaded');
$uh->processRequest();

Dmitry.Obukhov  
#2 Posted : Wednesday, November 9, 2011 9:39:35 PM(UTC)
Dmitry.Obukhov

Rank: Advanced Member

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

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

To receive width and height of thumbnails on the server side, you should get them from fields. Please look at my code snippet:

Code:

$width = $uploadedFile->getPackage()->getPackageField('File0Width_' . $uploadedFile->getIndex());
$height = $uploadedFile->getPackage()->getPackageField('File0Height_' . $uploadedFile->getIndex());
$xmlFile->setAttribute('width', $width);
$xmlFile->setAttribute('height', $height);
…

Where File0Width_Index and File0Height_Index are names of necessary fields with width/height of converted files #0. If you send several thumbnails (converters), and need to know their width/height, you should use indexes for them. For example, you have two converters. In this case, you will use this code:

Code:

$width0 = $uploadedFile->getPackage()->getPackageField('File0Width_' . $uploadedFile->getIndex());
$height0 = $uploadedFile->getPackage()->getPackageField('File0Height_' . $uploadedFile->getIndex());
$width1 = $uploadedFile->getPackage()->getPackageField('File1Width_' . $uploadedFile->getIndex());
$height1 = $uploadedFile->getPackage()->getPackageField('File1Height_' . $uploadedFile->getIndex());
…

If you need to get width/height of converted image on the client side, you should calculate these values using BeforeUpload and BeforePackageUpload events.

If you have any additional questions or problems, please feel free to let me know.

Edited by user Wednesday, November 9, 2011 9:40:35 PM(UTC)  | Reason: Not specified

Best regards,

Dmitry Obukhov

Technical Support. Aurigma, Inc.

bgordon  
#3 Posted : Wednesday, November 9, 2011 10:19:38 PM(UTC)
bgordon

Rank: Newbie

Groups: Member
Joined: 9/28/2011(UTC)
Posts: 5

Perfect. I was unsure how to get to those fields server-side. I saw them in the array but was unsure of the syntax. Works perfectly and applies to all the other data that is in that array! Thanks!
Dmitry.Obukhov  
#4 Posted : Wednesday, November 9, 2011 10:44:00 PM(UTC)
Dmitry.Obukhov

Rank: Advanced Member

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

Thanks: 8 times
Was thanked: 111 time(s) in 111 post(s)
Thanks, Bill, for your comment.
Best regards,

Dmitry Obukhov

Technical Support. Aurigma, Inc.

Users browsing this topic
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.