Exemple #1
0
    /**
     * @url GET /:prj_uid/export
     *
     * @param string $prj_uid {@min 32}{@max 32}
     */
    public function export($prj_uid)
    {
        $exporter = new \ProcessMaker\Exporter\XmlExporter($prj_uid);
        $getProjectName = $exporter->truncateName($exporter->getProjectName(),false);

        $outputDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP;
        $version = \ProcessMaker\Util\Common::getLastVersion($outputDir . $getProjectName . "-*.pmx") + 1;
        $outputFilename = $outputDir . sprintf("%s-%s.%s", str_replace(" ", "_", $getProjectName), $version, "pmx");

        $exporter->setMetadata("export_version", $version);
        $outputFilename = $outputDir.$exporter->saveExport($outputFilename);

        $httpStream = new \ProcessMaker\Util\IO\HttpStream();
        $fileExtension = pathinfo($outputFilename, PATHINFO_EXTENSION);

        $httpStream->loadFromFile($outputFilename);
        $httpStream->setHeader("Content-Type", "application/xml; charset=UTF-8");
        $httpStream->send();
    }
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
 * Coral Gables, FL, 33134, USA, or email info@colosa.com.
 */
if (!isset($_GET["file_hash"])) {
    throw new Exception("Invalid Request, param 'file_hash' was not sent.");
}
$httpStream = new \ProcessMaker\Util\IO\HttpStream();
$outputDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP;
$filename = base64_decode($_GET["file_hash"]);
$fileExtension = pathinfo($outputDir . $filename, PATHINFO_EXTENSION);
if (!file_exists($outputDir . $filename)) {
    throw new Exception("Error, couldn't find request file: {$filename}");
}
$httpStream->loadFromFile($outputDir . $filename);
$httpStream->setHeader("Content-Type", "application/{$fileExtension}");
$httpStream->send();
//  ************* DEPRECATED (it will be removed soon) *********************************
//add more security, and catch any error or exception
//$sFileName = $_GET['p'] . '.pm';
//$file = PATH_DOCUMENT . 'output' . PATH_SEP . $sFileName . 'tpm';
//$filex = PATH_DOCUMENT . 'output' . PATH_SEP . $sFileName;
//
//if (file_exists( $file )) {
//    rename( $file, $filex );
//}
//
//$realPath = PATH_DOCUMENT . 'output' . PATH_SEP . $sFileName;
//G::streamFile( $realPath, true );