Index: admin_templates/js/uploader/upload_manager.js =================================================================== --- admin_templates/js/uploader/upload_manager.js (revision 13557) +++ admin_templates/js/uploader/upload_manager.js (working copy) @@ -333,6 +333,16 @@ ) } +UploadsManager.onUploadSuccess = function(file, serverData, receivedResponse) { + var $uploader = UploadsManager._getUploader(file); + + $uploader.queueEvent( + function() { + this.UploadSuccess(file, serverData, receivedResponse); + } + ); +} + UploadsManager.onUploadError = function(file, errorCode, message) { var $uploader = UploadsManager._getUploader(file); Index: admin_templates/js/uploader/uploader.js =================================================================== --- admin_templates/js/uploader/uploader.js (revision 13557) +++ admin_templates/js/uploader/uploader.js (working copy) @@ -175,7 +175,7 @@ SWFUpload.instances[this.flash_id].uploadStart = UploadsManager.onUploadStart; SWFUpload.instances[this.flash_id].uploadProgress = UploadsManager.onUploadProgress; SWFUpload.instances[this.flash_id].uploadError = UploadsManager.onUploadError; - SWFUpload.instances[this.flash_id].uploadSuccess = UploadsManager.onHandleEverything; + SWFUpload.instances[this.flash_id].uploadSuccess = UploadsManager.onUploadSuccess; SWFUpload.instances[this.flash_id].uploadComplete = UploadsManager.onUploadComplete; SWFUpload.instances[this.flash_id].debug = UploadsManager.onDebug; @@ -497,7 +497,21 @@ this.remaining.innerHTML = this._formatTime( this._getEstimatedTime() ); } +Uploader.prototype.UploadSuccess = function(file, serverData, receivedResponse) { + if (!receivedResponse) { + return ; + } + + for (var f = 0; f < this.files.length; f++) { + if (this.files[f].id == file.id) { + // new uploaded file name returned by OnUploadFile event + this.files[f].name = serverData; + } + } +} + Uploader.prototype.UploadFileComplete = function(file) { + // file was uploaded OR file upload was cancelled this.uploaded += this.cur_file_uploaded; for (var f = 0; f < this.files.length; f++) { if (this.files[f].id == file.id) { Index: kernel/db/db_event_handler.php =================================================================== --- kernel/db/db_event_handler.php (revision 13581) +++ kernel/db/db_event_handler.php (working copy) @@ -2583,19 +2583,21 @@ { $event->status = erSTOP; define('DBG_SKIP_REPORTING', 1); - echo "Flash requires that we output something or it won't fire the uploadSuccess event"; + $default_msg = "Flash requires that we output something or it won't fire the uploadSuccess event"; if (!$this->Application->HttpQuery->Post) { // Variables {field, id, flashsid} are always submitted through POST! // When file size is larger, then "upload_max_filesize" (in php.ini), // then theese variables also are not submitted -> handle such case. header('HTTP/1.0 413 File size exceeds allowed limit'); + echo $default_msg; return ; } if (!$this->_checkFlashUploaderPermission($event)) { // 403 Forbidden header('HTTP/1.0 403 You don\'t have permissions to upload'); + echo $default_msg; return ; } @@ -2605,14 +2607,16 @@ // 413 Request Entity Too Large (file uploads disabled OR uploaded file was // to large for web server to accept, see "upload_max_filesize" in php.ini) header('HTTP/1.0 413 File size exceeds allowed limit'); + echo $default_msg; return ; } $tmp_path = WRITEABLE . '/tmp/'; $fname = $value['name']; $id = $this->Application->GetVar('id'); + if ($id) { - $fname = $id.'_'.$fname; + $fname = $id . '_' . $fname; } $fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); @@ -2622,13 +2626,39 @@ // 500 Internal Server Error // check both temp and live upload directory header('HTTP/1.0 500 Write permissions not set on the server'); + echo $default_msg; return ; } + $upload_formatter =& $this->Application->recallObject('kUploadFormatter'); + /* @var $upload_formatter kUploadFormatter */ + + $fname = $upload_formatter->_ensureUniqueFilename($tmp_path, $fname); + move_uploaded_file($value['tmp_name'], $tmp_path.$fname); + echo preg_replace('/^' . preg_quote($id, '/') . '_/', '', $fname); + + $this->deleteTempFiles($tmp_path); } /** + * Delete temporary files, that won't be used for sure + * + * @param string $path + */ + function deleteTempFiles($path) + { + $files = glob($path . '*.*'); + $max_file_date = strtotime('-1 day'); + + foreach ($files as $file) { + if (filemtime($file) < $max_file_date) { + unlink($file); + } + } + } + + /** * Checks, that flash uploader is allowed to perform upload * * @param kEvent $event @@ -2720,6 +2750,7 @@ header('Content-Length: '.filesize($path)); header('Content-Type: '.$type); + header('Content-Disposition: inline; filename="' . $file . '"'); safeDefine('DBG_SKIP_REPORTING',1);