本文整理汇总了PHP中KTUtil::download方法的典型用法代码示例。如果您正苦于以下问题:PHP KTUtil::download方法的具体用法?PHP KTUtil::download怎么用?PHP KTUtil::download使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KTUtil
的用法示例。
在下文中一共展示了KTUtil::download方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: downloadZipFile
/**
* Download the zip file
*/
function downloadZipFile($exportCode = NULL)
{
if (!(isset($exportCode) && !empty($exportCode))) {
$exportCode = KTUtil::arrayGet($_SESSION['zipcompression'], 'exportcode');
}
$aData = KTUtil::arrayGet($_SESSION['zipcompression'], $exportCode);
if (!empty($aData)) {
$sZipFile = $aData['file'];
$sTmpPath = $aData['dir'];
} else {
$sZipFile = $this->sZipFile;
$sTmpPath = $this->sTmpPath;
}
if (!file_exists($sZipFile)) {
return PEAR::raiseError(_kt('The zip file has not been created, if you are downloading a large number of documents
or a large document then it may take a few minutes to finish.'));
}
$mimeType = 'application/zip; charset=utf-8;';
$fileSize = filesize($sZipFile);
$fileName = $this->sZipFileName . '.' . $this->extension;
KTUtil::download($sZipFile, $mimeType, $fileSize, $fileName);
KTUtil::deleteDirectory($sTmpPath);
return true;
}
示例2: downloadVersion
function downloadVersion($oDocument, $iVersionId)
{
//get the document
$oContentVersion = KTDocumentContentVersion::get($iVersionId);
$oConfig =& KTConfig::getSingleton();
$sPath = sprintf("%s/%s", $oConfig->get('urls/documentRoot'), $this->getPath($oContentVersion));
$sVersion = sprintf("%d.%d", $oContentVersion->getMajorVersionNumber(), $oContentVersion->getMinorVersionNumber());
$mimeType = KTMime::getMimeTypeName($oContentVersion->getMimeTypeID());
$fileSize = $oContentVersion->getFileSize();
$fileName = $sVersion . '-' . $oContentVersion->getFileName();
return KTUtil::download($sPath, $mimeType, $fileSize, $fileName);
}
示例3: downloadZipFile
/**
* Download the zip file
*/
function downloadZipFile($exportCode = NULL)
{
if (!(isset($exportCode) && !empty($exportCode))) {
$exportCode = KTUtil::arrayGet($_SESSION['zipcompression'], 'exportcode');
}
$aData = KTUtil::arrayGet($_SESSION['zipcompression'], $exportCode);
if (!empty($aData)) {
$sZipFile = $aData['file'];
$sTmpPath = $aData['dir'];
} else {
$sZipFile = $this->sZipFile;
$sTmpPath = $this->sTmpPath;
}
if (!file_exists($sZipFile)) {
return PEAR::raiseError(_kt('The ZIP file can only be downloaded once - if you cancel the download, you will need to reload the page.'));
}
$mimeType = 'application/zip; charset=utf-8;';
$fileSize = filesize($sZipFile);
$fileName = $this->sZipFileName . '.zip';
KTUtil::download($sZipFile, $mimeType, $fileSize, $fileName);
KTUtil::deleteDirectory($sTmpPath);
return true;
}
示例4: do_pdfdownload_deprecated
/**
* Method for downloading the document as a pdf.
*
* @deprecated
* @return true on success else false
*/
function do_pdfdownload_deprecated()
{
$oDocument = $this->oDocument;
$oStorage =& KTStorageManagerUtil::getSingleton();
$oConfig =& KTConfig::getSingleton();
$default = realpath(str_replace('\\', '/', KT_DIR . '/../openoffice/program'));
putenv('ooProgramPath=' . $oConfig->get('openoffice/programPath', $default));
$cmdpath = KTUtil::findCommand('externalBinary/python');
// Check if openoffice and python are available
if ($cmdpath == false || !file_exists($cmdpath) || empty($cmdpath)) {
// Set the error messsage and redirect to view document
$this->addErrorMessage(_kt('An error occurred generating the PDF - please contact the system administrator. Python binary not found.'));
redirect(generateControllerLink('viewDocument', sprintf('fDocumentId=%d', $oDocument->getId())));
exit(0);
}
//get the actual path to the document on the server
$sPath = sprintf("%s/%s", $oConfig->get('urls/documentRoot'), $oStorage->getPath($oDocument));
if (file_exists($sPath)) {
// Get a tmp file
$sTempFilename = tempnam('/tmp', 'ktpdf');
// We need to handle Windows differently - as usual ;)
if (substr(PHP_OS, 0, 3) == 'WIN') {
$cmd = "\"" . $cmdpath . "\" \"" . KT_DIR . "/bin/openoffice/pdfgen.py\" \"" . $sPath . "\" \"" . $sTempFilename . "\"";
$cmd = str_replace('/', '\\', $cmd);
// TODO: Check for more errors here
// SECURTIY: Ensure $sPath and $sTempFilename are safe or they could be used to excecute arbitrary commands!
// Excecute the python script. TODO: Check this works with Windows
$res = `"{$cmd}" 2>&1`;
//print($res);
//print($cmd);
//exit;
} else {
// TODO: Check for more errors here
// SECURTIY: Ensure $sPath and $sTempFilename are safe or they could be used to excecute arbitrary commands!
// Excecute the python script.
$cmd = $cmdpath . ' ' . KT_DIR . '/bin/openoffice/pdfgen.py ' . escapeshellcmd($sPath) . ' ' . escapeshellcmd($sTempFilename);
$res = shell_exec($cmd . " 2>&1");
//print($res);
//print($cmd);
//exit;
}
// Check the tempfile exists and the python script did not return anything (which would indicate an error)
if (file_exists($sTempFilename) && $res == '') {
$mimetype = 'application/pdf';
$size = filesize($sTempFilename);
$name = substr($oDocument->getFileName(), 0, strrpos($oDocument->getFileName(), '.')) . '.pdf';
KTUtil::download($sTempFilename, $mimetype, $size, $name);
// Remove the tempfile
unlink($sTempFilename);
// Create the document transaction
$oDocumentTransaction =& new DocumentTransaction($oDocument, 'Document downloaded as PDF', 'ktcore.transactions.download', $aOptions);
$oDocumentTransaction->create();
// Just stop here - the content has already been sent.
exit(0);
} else {
// Set the error messsage and redirect to view document
$this->addErrorMessage(_kt('An error occurred generating the PDF - please contact the system administrator. ' . $res));
redirect(generateControllerLink('viewDocument', sprintf('fDocumentId=%d', $oDocument->getId())));
exit(0);
}
} else {
// Set the error messsage and redirect to view document
$this->addErrorMessage(_kt('An error occurred generating the PDF - please contact the system administrator. The path to the document did not exist.'));
redirect(generateControllerLink('viewDocument', sprintf('fDocumentId=%d', $oDocument->getId())));
exit(0);
}
}