Categories | Question details Back To List | ||
Vault not uploading I'm trying to get the vault to upload files. It worked twice but now doesn't work at all. The 2 times it worked I had commented out the lines where I create a document record in the database. Doing this now though has no effect. If I don't comment out the session related lines, for example session_name($id); session_start(); I get an error saying that there is already a session (I'm using Symfony which has already created a session). If I do comment out all of the session related lines the handlers work as follows getUploadIdHandler returns id correctly getUploadInfoHandler always returns 0 uploadHandler never executes Even if you can't recreate this problem can you point me to where I should start looking? Also, is there any way of returning values into the onUploadComplete function? I need to get the primary keys of the document records created in executeUploadHandler and process them in onUploadComplete. new Form.EventObserver('documentform', copyFormValuesToVault); function copyFormValuesToVault(element, value){ vault.setFormField('vault_doc[title]', Form.Element.getValue(document.getElementById('document_title'))); vault.setFormField('vault_doc[document_category_id]', Form.Element.getValue(document.getElementById('document_document_category_id'))); vault.setFormField('vault_doc[description]', Form.Element.getValue(document.getElementById('document_description'))); vault.setFormField('vault_doc[vendor_id]', Form.Element.getValue(docuonUploadCompletement.getElementById('document_vendor_id'))); vault.setFormField('vault_doc[purchase_id]', Form.Element.getValue(document.getElementById('document_purchase_id'))); vault.setFormField('vault_doc[client_id]', Form.Element.getValue(document.getElementById('document_client_id'))); vault.setFormField('vault_doc[job_id]', Form.Element.getValue(document.getElementById('document_job_id'))); vault.setFormField('vault_doc[task_id]', Form.Element.getValue(document.getElementById('document_task_id'))); vault.setFormField('vault_doc[sale_id]', Form.Element.getValue(document.getElementById('document_sale_id'))); vault.setFormField('vault_doc[sa_client_id]', Form.Element.getValue(document.getElementById('document_sa_client_id'))); vault.setFormField('vault_doc[created_by_id]', Form.Element.getValue(document.getElementById('document_created_by_id'))); vault.setFormField('vault_doc[ordering]', Form.Element.getValue(document.getElementById('document_ordering'))); vault.setFormField('vault_doc[is_active]', Form.Element.getValue(document.getElementById('document_is_active'))); } vault = new dhtmlXVaultObject(); vault.setImagePath(dhtmlx_codebase_path+'imgs/'); vault.setServerHandlers( "<?php echo url_for("document/uploadHandler") ?>", "<?php echo url_for("document/getUploadInfoHandler") ?>", "<?php echo url_for("document/getUploadIdHandler") ?>" ); vault.onUploadComplete = function(files){ parent.loadCurrentChildTab(true); // var update_ids = ''; // for (var i=0; i<files.length; i++){ // var file = files[i]; // if (file.uploaded == true && file.error == false) // update_ids += file.id+','+file.name+' '; // } // alert('onUploadComplete update_ids '+update_ids); }; vault.create("vaultDiv"); copyFormValuesToVault(); </script> The PHP handler functions appear below. public function executeUploadHandler() { $request = $this->getRequest(); $this->setLayout(false); $this->getResponse()->setHttpHeader('Content-Type','text/plain; charset=utf-8'); $id = $_GET['sessionId']; $id = trim($id); session_name($id); session_start(); $inputName = $_GET['userfile']; $fileName = $_FILES[$inputName]['name']; $tempLoc = $_FILES[$inputName]['tmp_name']; $path_parts = pathinfo($filename); $file = $path_parts['filename']; $extension = $path_parts['extension']; echo $_FILES[$inputName]['error']; $form_doc = $this->getRequestParameter('vault_doc'); if (strlen($form_doc['title']) == 0) $form_doc['title'] = $file; if (strlen($form_doc['document_category_id']) == 0) $form_doc['document_category_id'] = DocumentCategoryPeer::CATEGORY_USER_DEFINED; $document = new Document(); $document->setTitle($form_doc['title']); $document->setDocumentCategoryId($form_doc['document_category_id']); $document->setDescription($form_doc['description']); $document->setFileName(basename($fileName)); $document->setFileExtension($extension); $document->setVendorId($form_doc['vendor_id']); $document->setPurchaseId($form_doc['purchase_id']); $document->setClientId($form_doc['client_id']); $document->setJobId($form_doc['job_id']); $document->setTaskId($form_doc['task_id']); $document->setSaleId($form_doc['sale_id']); $document->setSaClientId($form_doc['sa_client_id']); $document->setCreatedById($form_doc['created_by_id']); $document->setOrdering($form_doc['ordering']); $document->setIsActive($form_doc['is_active']); $document = $document->save(); $target_path = DocumentPeer::getDocumentDirectorySaClientRoot(); $target_path = $target_path . self::doFormatDocumentId($document->getId()).'.'.$extension;//basename($fileName); if(move_uploaded_file($tempLoc,$target_path)) { $_SESSION['dhxvlt_state'] = -1; } else { $_SESSION['dhxvlt_state'] = -3; } return $this->renderText($_FILES[$inputName]['error']); } public function executeGetUploadInfoHandler() { $this->setLayout(false); $this->getResponse()->setHttpHeader('Content-Type','text/plain; charset=utf-8'); $id = $_POST['sessionId']; $id = trim($id); session_name($id); // session_start(); if($_SESSION['dhxvlt_state']==-1) { // -1 is set in UploadHandler.php after a successful upload // send 100% back and mark state for invalidation $_SESSION['dhxvlt_state'] = -2; return $this->renderText(100); } else if($_SESSION['dhxvlt_state']==-2) { // -2 is set above to invalidate current upload session return $this->renderText(-1); // session_destroy(); } else if($_SESSION['dhxvlt_state']==-3) { // -3 is set in UploadHandler.php in case of some error (like filename encoding, "post_max_size" oversized). $maxPost = ini_get('post_max_size'); return $this->renderText("error:-3:$maxPost:"); // session_destroy(); } else { $info = uploadprogress_get_info($id); $bt = $info['bytes_total']; if ($bt < 1) { $percent = 0; } else { if (!$_SESSION['dhxvlt_max']) { // check the upload_max_filesize config value $_SESSION['dhxvlt_max'] = true; $maxSizeM = ini_get('upload_max_filesize'); $maxSize = DocumentPeer::getBytes($maxSizeM); if ($maxSize<$bt) { $_SESSION['dhxvlt_state'] = -2; return $this->renderText( "error:-2:$bt:$maxSizeM:"); } } $percent = round($info['bytes_uploaded'] / $bt * 100, 0); } return $this->renderText($percent); } } public function executeGetUploadIdHandler() { $this->setLayout(false); $this->getResponse()->setHttpHeader('Content-Type','text/plain; charset=utf-8'); $id = uniqid('id'); session_name($id); // session_start(); $_SESSION['dhxvlt_state'] = 0; return $this->renderText($id); } Answer posted by Support on Nov 23, 2009 05:45 You may skip session creation code, use your existing session mechanism instead. But then, you should handle all session related code yourself. We use session to store temporary data about current file being uploaded. I can see that you are doing something like this in your current code. Just double check it so it has no errors. Answer posted on Nov 27, 2009 13:37 Thanks. The problem was that there was an error in my code when saving the $document record to the database. As a result move_uploaded_file was never executed. The result was that uploadprogress_get_info always returned false and the whole thing just kept looping becuase $_SESSION['dhxvlt_state'] was never set to anything other than 0. It would be great if custom errors could be returned from executeUploadHandler() so that a javascript alert could be displayed to the user. It would also be great if other info could be passed from executeUploadHandler() on success. e.g. in my case I would like to have access to the id of the newly created database record. Answer posted by Support on Nov 30, 2009 08:29 Yes, you are absolutely right in your proposals. We have added this possibility in the latest development version. Thank you! |