* @see WCF.Upload._success()
*/
_success: function(uploadID, data) {
- for (var $i = 0; $i < this._uploadMatrix[uploadID].length; $i++) {
+ for (var $i in this._uploadMatrix[uploadID]) {
// get li
var $li = this._uploadMatrix[uploadID][$i];
// get filename and check result
var $filename = $li.data('filename');
- if (data.returnValues && data.returnValues['attachments'][$filename]) {
+ var $internalFileID = $li.data('internalFileID');
+ if (data.returnValues && data.returnValues.attachments[$internalFileID]) {
// show thumbnail
- if (data.returnValues['attachments'][$filename]['tinyURL']) {
- $li.children('.icon-spinner').replaceWith($('<img src="' + data.returnValues['attachments'][$filename]['tinyURL'] + '" alt="" class="attachmentTinyThumbnail" />'));
+ if (data.returnValues.attachments[$internalFileID]['tinyURL']) {
+ $li.children('.icon-spinner').replaceWith($('<img src="' + data.returnValues.attachments[$internalFileID]['tinyURL'] + '" alt="" class="attachmentTinyThumbnail" />'));
}
// show file icon
else {
// update attachment link
var $link = $('<a href=""></a>');
- $link.text($filename).attr('href', data.returnValues['attachments'][$filename]['url']);
+ $link.text($filename).attr('href', data.returnValues.attachments[$internalFileID]['url']);
- if (data.returnValues['attachments'][$filename]['isImage'] != 0) {
- console.debug(data.returnValues['attachments'][$filename]['isImage']);
+ if (data.returnValues.attachments[$internalFileID]['isImage'] != 0) {
$link.addClass('jsImageViewer').attr('title', $filename);
}
$li.find('p').empty().append($link);
// update file size
- $li.find('small').append(data.returnValues['attachments'][$filename]['formattedFilesize']);
+ $li.find('small').append(data.returnValues.attachments[$internalFileID]['formattedFilesize']);
// init buttons
- var $deleteButton = $('<li><span class="icon icon16 icon-remove pointer jsTooltip jsDeleteButton" title="'+WCF.Language.get('wcf.global.button.delete')+'" data-object-id="'+data.returnValues['attachments'][$filename]['attachmentID']+'" data-confirm-message="'+WCF.Language.get('wcf.attachment.delete.sure')+'" /></li>');
+ var $deleteButton = $('<li><span class="icon icon16 icon-remove pointer jsTooltip jsDeleteButton" title="'+WCF.Language.get('wcf.global.button.delete')+'" data-object-id="'+data.returnValues.attachments[$internalFileID]['attachmentID']+'" data-confirm-message="'+WCF.Language.get('wcf.attachment.delete.sure')+'" /></li>');
$li.find('ul').append($deleteButton);
if (this._wysiwygContainerID) {
- var $insertButton = $('<li><span class="icon icon16 icon-paste pointer jsTooltip jsButtonInsertAttachment" title="' + WCF.Language.get('wcf.attachment.insert') + '" data-object-id="' + data.returnValues['attachments'][$filename]['attachmentID'] + '" /></li>');
+ var $insertButton = $('<li><span class="icon icon16 icon-paste pointer jsTooltip jsButtonInsertAttachment" title="' + WCF.Language.get('wcf.attachment.insert') + '" data-object-id="' + data.returnValues.attachments[$internalFileID]['attachmentID'] + '" /></li>');
$insertButton.children('.jsButtonInsertAttachment').click($.proxy(this._insert, this));
$li.find('ul').append($insertButton);
}
var $errorMessage = '';
// error handling
- if (data.returnValues && data.returnValues['errors'][$filename]) {
- $errorMessage = data.returnValues['errors'][$filename]['errorType'];
+ if (data.returnValues && data.returnValues.errors[$internalFileID]) {
+ $errorMessage = data.returnValues.errors[$internalFileID]['errorType'];
}
else {
// unknown error
*/
_iframe: null,
+ /**
+ * internal file id
+ * @var integer
+ */
+ _internalFileID: 0,
+
/**
* additional options
* @var jQuery
this._buttonSelector = buttonSelector;
this._fileListSelector = fileListSelector;
this._className = className;
+ this._internalFileID = 0;
this._options = $.extend(true, {
action: 'upload',
multiple: false,
return;
}
- var $validFilenames = [ ];
- for (var $i = 0, $length = this._uploadMatrix[$uploadID].length; $i < $length; $i++) {
- var $li = this._uploadMatrix[$uploadID][$i];
- if (!$li.hasClass('uploadFailed')) {
- $validFilenames.push($li.data('filename'));
- }
- }
-
for (var $i = 0, $length = $files.length; $i < $length; $i++) {
- if ($validFilenames.indexOf($files[$i].name) !== -1) {
- $fd.append('__files[]', $files[$i]);
+ if (this._uploadMatrix[$uploadID][$i]) {
+ var $internalFileID = this._uploadMatrix[$uploadID][$i].data('internalFileID');
+ $fd.append('__files[' + $internalFileID + ']', $files[$i]);
}
}
$fd.append('className', this._className);
var $additionalParameters = this._getParameters();
for (var $name in $additionalParameters) {
- $fd.append('parameters['+$name+']', $additionalParameters[$name]);
+ $fd.append('parameters[' + $name + ']', $additionalParameters[$name]);
}
var self = this;
var $li = this._initFile($file);
if (!$li.hasClass('uploadFailed')) {
- $li.data('filename', $file.name);
- this._uploadMatrix[$uploadID].push($li);
+ $li.data('filename', $file.name).data('internalFileID', this._internalFileID++);
+ this._uploadMatrix[$uploadID][$i] = $li;
}
}
_progress: function(uploadID, event) {
var $percentComplete = Math.round(event.loaded * 100 / event.total);
- for (var $i = 0; $i < this._uploadMatrix[uploadID].length; $i++) {
+ for (var $i in this._uploadMatrix[uploadID]) {
this._uploadMatrix[uploadID][$i].find('progress').attr('value', $percentComplete);
}
},
EventHandler::getInstance()->fireAction($this, 'checkThumbnail');
if ($this->eventData['hasThumbnail']) $thumbnails[] = $attachment;
}
- $attachments[] = $attachment;
+ $attachments[$file->getInternalFileID()] = $attachment;
}
else {
// moving failed; delete attachment
$result = array('attachments' => array(), 'errors' => array());
if (!empty($attachments)) {
// get attachment ids
- $attachmentIDs = array();
- foreach ($attachments as $attachment) $attachmentIDs[] = $attachment->attachmentID;
+ $attachmentIDs = $attachmentToFileID = array();
+ foreach ($attachments as $internalFileID => $attachment) {
+ $attachmentIDs[] = $attachment->attachmentID;
+ $attachmentToFileID[$attachment->attachmentID] = $internalFileID;
+ }
// get attachments from database (check thumbnail status)
$attachmentList = new AttachmentList();
$attachmentList->readObjects();
foreach ($attachmentList as $attachment) {
- $result['attachments'][$attachment->filename] = array(
+ $result['attachments'][$attachmentToFileID[$attachment->attachmentID]] = array(
'filename' => $attachment->filename,
'filesize' => $attachment->filesize,
'formattedFilesize' => FileUtil::formatFilesize($attachment->filesize),
}
foreach ($failedUploads as $failedUpload) {
- $result['errors'][$failedUpload->getFilename()] = array(
+ $result['errors'][$failedUpload->getInternalFileID()] = array(
'filename' => $failedUpload->getFilename(),
'filesize' => $failedUpload->getFilesize(),
'errorType' => $failedUpload->getValidationErrorType()
*/
protected $filename = '';
+ /**
+ * internal file id
+ * @var integer
+ */
+ protected $internalFileID = 0;
+
/**
* location of the uploaded file
* @var string
* @param string $mimeType
*/
public function __construct($filename, $location, $filesize, $errorCode = 0, $mimeType = '') {
+ if (preg_match('~^__wcf_([0-9]+)_(.*)~', $filename, $matches)) {
+ $this->internalFileID = $matches[1];
+ $filename = $matches[2];
+ }
+
$this->filename = $filename;
$this->location = $location;
$this->filesize = $filesize;
return $this->filename;
}
+ /**
+ * Returns internal file id.
+ *
+ * @return integer
+ */
+ public function getInternalFileID() {
+ return $this->internalFileID;
+ }
+
/**
* Returns the extension of the original file name.
*
*/
protected function __construct(array $rawFileData) {
if (is_array($rawFileData['name'])) {
+ // iOS work-around
+ $newRawFileData = array(
+ 'name' => array(),
+ 'type' => array(),
+ 'tmp_name' => array(),
+ 'error' => array(),
+ 'size' => array()
+ );
+ $i = 0;
+ foreach (array_keys($rawFileData['name']) as $internalFileID) {
+ $newRawFileData['name'][$i] = '__wcf_' . $internalFileID . '_' . $rawFileData['name'][$internalFileID]; // __wcf_X_filename.ext
+ $newRawFileData['type'][$i] = $rawFileData['type'][$internalFileID];
+ $newRawFileData['tmp_name'][$i] = $rawFileData['tmp_name'][$internalFileID];
+ $newRawFileData['error'][$i] = $rawFileData['error'][$internalFileID];
+ $newRawFileData['size'][$i] = $rawFileData['size'][$internalFileID];
+
+ $i++;
+ }
+ $rawFileData = $newRawFileData;
+
// multiple uploads
for ($i = 0, $l = count($rawFileData['name']); $i < $l; $i++) {
$this->files[] = new UploadFile($rawFileData['name'][$i], $rawFileData['tmp_name'][$i], $rawFileData['size'][$i], $rawFileData['error'][$i], ($rawFileData['tmp_name'][$i] ? (FileUtil::getMimeType($rawFileData['tmp_name'][$i]) ?: $rawFileData['type'][$i]) : ''));