private function putfile() { require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_onepage' . DS . 'assets' . DS . 'export_helper.php'; $ehelper = new OnepageTemplateHelper(); // no direct access // POST: tid, localid, file, hash, $tid = JRequest::getVar('tid'); $localid = JRequest::getVar('localid'); //$ehelper->setStatus($tid, $localid, 'RECEIVING'); $hash = JRequest::getVar('hash'); $hash2 = $ehelper->getFileHash($tid); $eitem = $ehelper->getExportItem($tid, $localid); $tt = $ehelper->getTemplate($tid); jimport('joomla.filesystem.file'); $tname = $tid; $tname = JFile::makesafe($tname); $ex = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_onepage' . DS . 'export' . DS; $exf = $ex . $tname; if (empty($_FILES)) { JFactory::getApplication()->close(); } if (strtolower($hash) == $hash2 && is_numeric($tid)) { $ehelper->prepareDirectory($tid); // here we should have autoincrement value instead of order id=local id $fileName = $_FILES['file_contents']['name']; $fileTemp = $_FILES['file_contents']['tmp_name']; $num = $eitem['ai']; if (!isset($num)) { $num = $localid; } else { $num = $num; } if (is_numeric($num)) { $num = $ehelper->addZeros($num, 4); } $tn = JFile::makesafe($tt['tid_name']); $path = $exf . DS . $num . '_' . $tn . '.pdf'; $path = $ehelper->getFileName2Save($tid, $localid); if (file_exists($path)) { $xt = rand(); JFile::move($path, $path . '_history_' . $xt . '.bck'); //JFile::delete($path); } if (!JFile::upload($fileTemp, $path)) { $ehelper->setStatus($tid, $localid, 'ERROR'); echo 'Error saving file!'; //JFile::write($exf.DS.'log'.DS.'log.txt', var_export($fileTemp, true)); } else { //echo 'Saving data: '.$tid.' '.$localid.' '.$path; // here we can send it to a customer $tt = $ehelper->getTemplate($tid); if ($ehelper->getStatus($tid, $localid) == 'AUTOPROCESSING') { if (!empty($tt['tid_autocreate']) && !empty($tt['tid_email'])) { $ehelper->setStatus($tid, $localid, 'CREATED', urlencode($path)); ob_start(); $ehelper->sendMail($tid, $localid, false); $x = ob_get_clean(); //JFile::write($exf.DS.'log'.DS.'log.txt', 'sending mail'.$x); //$ehelper->syntaxError(); } } $ehelper->setStatus($tid, $localid, 'CREATED', urlencode($path)); echo 'File Saved OK!'; } //file_put_contents($exf.DS.$localid.'_'.$tname.'.pdf', $file); /* else { echo 'ERROR: Nothing to save!'; } */ JFactory::getApplication()->close(); } else { JFile::write($exf . DS . 'log' . DS . 'log.txt', 'secret not equal'); $ehelper->setStatus($tid, $localid, 'ERROR'); echo 'Secret not equal !'; JFactory::getApplication()->close(); } }