Commit 75afd5db authored by Carsten  Rose's avatar Carsten Rose
Browse files

Upload: fixed bug that pathfilenames in table are overwritten with SIP id after reload and save.

CODING.md: edited to be more clearly.
AbstractBuildForm.php: doc
Save.php: If there is no upload, do not save the filename again (which needs to be calculated instead of using the sip)
parent 02fb2d00
......@@ -73,26 +73,27 @@ DELETE
<button type="button" class="record-delete" data-sip={{SIP}} ><span class="glyphicon glyphicon-trash"></span></button>
Form Build (load)
.................
* The upload functionality consist of three elements
* 1) A <div> tag with a) an optional filename of an earlier uploaded file plus and b) a trash Button.
* 2) The 'browse' button (<input type='file' name='_upload_<feName>'>). This element will not be send by post.
Upload
-----------------
* The upload UI consist of three elements
* 1) A <div> tag with a) an optional filename of an earlier uploaded file and b) a trash Button.
* 2) The 'browse' button (<input type='file' name='<feName>'>). This element will not be send by post.
* 3) A HTML hidden element with name=<feName> containing the <sipUpload>.
* A new uniq SIP (sipUpload) will be created for every upload formElement. These 'sipUpload' will be assigned to the browse button and to the delete button.
* The individual sipUpload is necessary to correctly handle multiple simustaenously forms when using r=0. Also, through this uniq id it's easy to distinguish between asynchron uploaded files.
* The SIP contains the '_FILES' information submitted during the upload.
* Via the hidden element <feName> 'save()' access the form individual upload status informations.
* A new uniq SIP (sipUpload) will be created for every upload formElement. These 'sipUpload' will be assigned to the upload browse button and to the upload delete button.
* The individual sipUpload is necessary to correctly handle multiple simultaenously forms when using r=0. Also, through this uniq id it's easy to distinguish between asynchron uploaded files.
* The SIP on ther server contains the individual '_FILES' information submitted during the upload.
* Via the hidden element <feName> 'save()', access to the form individual upload status informations is given.
Upload to server, before 'save'
...............................
* If a user open's a file for upload via the browse button, that file is immediately transmitted to the server. The user will see a turning wheel during the upload time.
* On success the 'Browse; Button disappears and the filename plus the delete button will be displayed (client logic).
* If a user open's a file for upload via the browse button, that file is immediately transmitted to the server. The user will see a turning wheel during until the upload finished.
* After successfull upload the 'Browse' button disappears and the filename, plus the delete button, will be displayed (client logic).
* The uploaded file will be checked: maxsize, mime type, check script.
* The uploaded file is still temporary. It has been renamed from $_SESSION['X'][<uploadSip>][FILES_TMP_NAME] to $_SESSION['X'][<uploadSip>][FILES_TMP_NAME].cached
* The upload action will be saved in the user session.
* $_SESSION['X'][<uploadSip>][FILES_TMP_NAME|FILES_NAME|FILES_ERROR|FILE_SIZE]
* Clicks the user on delete button.
* Clicks the user on delete button:
* In the usersession a flagDelete will be set: $_SESSION['X'][<uploadSip>]['flagDelete']='1'
* An optional previous upload file (still not saved on the final place) will be deleted.
* An optional existing variable $_SESSION['X'][<uploadSip>][FILES_TMP_NAME] will be deleted. The 'flagDelete' must not be change - it's later needed to detect to delete earlier uploaded files.
......
......@@ -1680,7 +1680,7 @@ abstract class AbstractBuildForm {
}
/**
* Builds an Upload (File) Button.
* Build an Upload (File) Button.
*
* @param array $formElement
* @param $htmlFormElementId
......@@ -1693,6 +1693,7 @@ abstract class AbstractBuildForm {
public function buildFile(array $formElement, $htmlFormElementId, $value, array &$json) {
$attribute = '';
# Build param array for uniq SIP
$arr = array();
$arr['fake_uniq_never_use_this'] = uniqid(); // make sure we get a new SIP. This is needed for multiple forms (same user) with r=0
$arr[CLIENT_SIP_FOR_FORM] = $this->store->getVar(SIP_SIP, STORE_SIP);
......
......@@ -134,6 +134,9 @@ class Save {
$file = $this->doUpload($formElement, $formValues[$column]);
if ($file !== false) {
$formValues[$column] = $file;
} else {
// if there was no new upload, do nothing on this field
unset ($formValues[$column]);
}
}
}
......@@ -151,7 +154,6 @@ class Save {
*/
private function doUpload($formElement, $sipUpload) {
// Status information about upload file
$statusUpload = $this->store->getVar($sipUpload, STORE_EXTRA);
if ($statusUpload === false) {
......@@ -196,6 +198,11 @@ class Save {
private function copyUploadFile(array $formElement, array $statusUpload) {
$pathFileName = '';
if (!isset($statusUpload[FILES_NAME])) {
// nothing to upload: e.g. user has deleted a previous uploaded file.
return '';
}
if (isset($formElement[FE_PATH_FILE_NAME])) {
// Provide variable '_filename'. Might be substituted in $formElement[FE_PATH_FILE_NAME].
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment