将 TCPDF 输出生成到共享驱动器文件夹
Generate TCPDF output to a shared drive folder
我正在尝试将我的 PDF 文件保存到 "Shared Folder",我正在使用配置文件来设置 "Shared Folder" 然后我只是在 [=63= 中设置路径] 文件。
但是它不允许我使用 "Shared Folder" 路径保存,它给了我错误:
Failed to open stream: No such file or directory
它适用于 "C:/Path name/"
,我不想这样做,因为我无法访问根文件夹。
从配置文件中创建路径名的值
SharedFolder = //MIA_TEST/htdocs/SharedFolder
我读取文件和创建文件夹结构:
// Code to get values from config
function GetDictionaryOfUnsignedValues()
{
$fp = fopen("C:/ISOSEC/serverLicense.txt","r");
if ($fp == false)
return null;
$UnsignedDataStarted = false;
$UnsignedDataFinished = false;
$UnsignedData = "";
// Read the licence file line by line and extract signed data block as well as signature
while (($line = fgets($fp, 4096)) !== FALSE)
{
if ($line == "ISOSEC NOT SIGNED:\n")
{
$UnsignedDataStarted = true;
continue;
}
if ($UnsignedDataStarted and !$UnsignedDataFinished)
{
// When we come across an empty line (line length > 2), the signed dat block is finished
if (strlen($line) > 2)
$UnsignedData = $UnsignedData . $line;
else
$UnsignedDataFinished = true;
}
}
fclose($fp);
// Split the whole signed data block line by line
$ArrayOfLines = explode ("\n",$UnsignedData);
// Get the signed data into php easily accessible code - dctionary (associative array)
$UnsignedDataDictionary = array();
foreach ($ArrayOfLines as $line)
{
// Only lines containing ' = ' are valid lines
if (strpos($line,' = ') !== false)
{
$keyValueArray = explode (" = ",$line);
$UnsignedDataDictionary[$keyValueArray[0]] = $keyValueArray[1];
}
}
if (count($UnsignedDataDictionary) < 1)
return NULL;
return $UnsignedDataDictionary;
}
// Create folder in folder
function createFolderInFolder($InputFolder, $newFolder)
{
if (!is_dir($InputFolder))
return NULL;
$CreatedFolder = $InputFolder . '/' .$newFolder;
//we don't want to rewrite the folder with new one if it already exist
if (file_exists ($CreatedFolder))
return $CreatedFolder;
$oldmask = umask(0);
if (mkdir($CreatedFolder, 0777))
{
umask($oldmask);
return $CreatedFolder;
}
else
return NULL;
}
// Obtain shared folder from config file
// Then create output folder (or check if exist the output folder)
$ServerConfigDictionary = GetDictionaryOfUnsignedValues();
if ($ServerConfigDictionary == NULL)
LogToLogFileAndFinishExecution("Discharge - Failed to obtain list of server configuration items from the server licence file");
if (!array_key_exists('SharedFolder', $ServerConfigDictionary))
LogToLogFileAndFinishExecution("Discharge - Failed to obtain Shared folder location item from the server licence file");
// Get the shared folder location from the server config file
$SharedFolder = $ServerConfigDictionary['SharedFolder'];
// Check database connection, if not established, output an error and finish the script
if ($connection == NULL)
LogToLogFileAndFinishExecution("Unable to establish database conection - unable to generate Postnatals");
if (($OutputFolder = createFolderInFolder($SharedFolder, "MIA - Digital Post Natal Records")) == NULL)
{
LogMessageToServerLog($connection, 'Failed to create or find folder to store Discharges in shared directory', "ERROR", "Discharge.php");
exit(0);
}
我正在使用 TCPDF 生成 PDF,这里是生成 PDF 的代码行
PDF代码1:
//PDF Output
$pdf->Output($OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . '_' . $Mother->PatientTableRecord['NHSID'] . ' ' . date('d_m_Y') . '.pdf'),'F'); // $OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . ' ' . date('d_m_Y h_i_s', time() . '.pdf','F');
响应1:
fopen(file:////MIA_TEST/htdocs/SharedFolder/MIA - Digital Post Natal Records/Fiona Appleton_1946546288 09_06_2015.pdf): failed to open stream: No such file or directory
PDF 代码 2:(添加了真实路径)
$pdf->Output(realpath($OutputFolderPath) . ReplaceWindowsFileNameSpecialCharacters($Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . '_' . $Mother->PatientTableRecord['NHSID'] . ' ' . date('d_m_Y') . '.pdf'),'F'); // $OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . ' ' . date('d_m_Y h_i_s', time()) . '.pdf','F');
回复2:
fopen(): remote host file access not supported, file://\MIA_TEST\HTDOCS\SharedFolder\MIA - Digital Post Natal RecordsFiona Appleton_1946546288 09_06_2015.pdf
PDF代码3:
// Worked
fopen($OutputFolderPath."Text.pdf", "w");
// Didn't work
$pdf->Output($OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . '_' . $Mother->PatientTableRecord['NHSID'] . ' ' . date('d_m_Y') . '.pdf','F'); // $OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . ' ' . date('d_m_Y h_i_s', time()) . '.pdf','F'
// Works with no PDF content inside
fopen($OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . '_' . $Mother->PatientTableRecord['NHSID'] . ' ' . date('d_m_Y') . '.pdf','F'); // $OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . ' ' . date('d_m_Y h_i_s', time()) . '.pdf','w');
响应 3:
fopen(file:////MIA_TEST/htdocs/SharedFolder/MIA - Digital Post Natal Records/Fiona Appleton_1946546288 09_06_2015.pdf): failed to open stream: No such file or directory
如果
//MIA_TEST/htdocs/SharedFolder
是一个有效的路径。保存 PDF 应该不会有任何问题。 PHP 无法找到您指定的路径。
尝试做一个简单的
fopen("//MIA_TEST/htdocs/SharedFolder/sample.txt", "w");
如果可行,那么您的问题就解决了。请确保路径正确。还要检查目标路径中是否有空格。
Output()
用下划线替换空格并删除特殊字符。您可能想确保这些事情的一切都是正确的。
http://www.tcpdf.org/doc/code/classTCPDF.html#a3d6dcb62298ec9d42e9125ee2f5b23a1
我发现我可以使用这个:
$savedOutput = file_get_contents('SavedOutput.pdf');
file_put_contents('newSavedOutput.pdf', $saveOutput);
我把PDF存到文件夹里,然后获取内容存到共享文件夹里
我正在尝试将我的 PDF 文件保存到 "Shared Folder",我正在使用配置文件来设置 "Shared Folder" 然后我只是在 [=63= 中设置路径] 文件。
但是它不允许我使用 "Shared Folder" 路径保存,它给了我错误:
Failed to open stream: No such file or directory
它适用于 "C:/Path name/"
,我不想这样做,因为我无法访问根文件夹。
从配置文件中创建路径名的值
SharedFolder = //MIA_TEST/htdocs/SharedFolder
我读取文件和创建文件夹结构:
// Code to get values from config
function GetDictionaryOfUnsignedValues()
{
$fp = fopen("C:/ISOSEC/serverLicense.txt","r");
if ($fp == false)
return null;
$UnsignedDataStarted = false;
$UnsignedDataFinished = false;
$UnsignedData = "";
// Read the licence file line by line and extract signed data block as well as signature
while (($line = fgets($fp, 4096)) !== FALSE)
{
if ($line == "ISOSEC NOT SIGNED:\n")
{
$UnsignedDataStarted = true;
continue;
}
if ($UnsignedDataStarted and !$UnsignedDataFinished)
{
// When we come across an empty line (line length > 2), the signed dat block is finished
if (strlen($line) > 2)
$UnsignedData = $UnsignedData . $line;
else
$UnsignedDataFinished = true;
}
}
fclose($fp);
// Split the whole signed data block line by line
$ArrayOfLines = explode ("\n",$UnsignedData);
// Get the signed data into php easily accessible code - dctionary (associative array)
$UnsignedDataDictionary = array();
foreach ($ArrayOfLines as $line)
{
// Only lines containing ' = ' are valid lines
if (strpos($line,' = ') !== false)
{
$keyValueArray = explode (" = ",$line);
$UnsignedDataDictionary[$keyValueArray[0]] = $keyValueArray[1];
}
}
if (count($UnsignedDataDictionary) < 1)
return NULL;
return $UnsignedDataDictionary;
}
// Create folder in folder
function createFolderInFolder($InputFolder, $newFolder)
{
if (!is_dir($InputFolder))
return NULL;
$CreatedFolder = $InputFolder . '/' .$newFolder;
//we don't want to rewrite the folder with new one if it already exist
if (file_exists ($CreatedFolder))
return $CreatedFolder;
$oldmask = umask(0);
if (mkdir($CreatedFolder, 0777))
{
umask($oldmask);
return $CreatedFolder;
}
else
return NULL;
}
// Obtain shared folder from config file
// Then create output folder (or check if exist the output folder)
$ServerConfigDictionary = GetDictionaryOfUnsignedValues();
if ($ServerConfigDictionary == NULL)
LogToLogFileAndFinishExecution("Discharge - Failed to obtain list of server configuration items from the server licence file");
if (!array_key_exists('SharedFolder', $ServerConfigDictionary))
LogToLogFileAndFinishExecution("Discharge - Failed to obtain Shared folder location item from the server licence file");
// Get the shared folder location from the server config file
$SharedFolder = $ServerConfigDictionary['SharedFolder'];
// Check database connection, if not established, output an error and finish the script
if ($connection == NULL)
LogToLogFileAndFinishExecution("Unable to establish database conection - unable to generate Postnatals");
if (($OutputFolder = createFolderInFolder($SharedFolder, "MIA - Digital Post Natal Records")) == NULL)
{
LogMessageToServerLog($connection, 'Failed to create or find folder to store Discharges in shared directory', "ERROR", "Discharge.php");
exit(0);
}
我正在使用 TCPDF 生成 PDF,这里是生成 PDF 的代码行
PDF代码1:
//PDF Output
$pdf->Output($OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . '_' . $Mother->PatientTableRecord['NHSID'] . ' ' . date('d_m_Y') . '.pdf'),'F'); // $OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . ' ' . date('d_m_Y h_i_s', time() . '.pdf','F');
响应1:
fopen(file:////MIA_TEST/htdocs/SharedFolder/MIA - Digital Post Natal Records/Fiona Appleton_1946546288 09_06_2015.pdf): failed to open stream: No such file or directory
PDF 代码 2:(添加了真实路径)
$pdf->Output(realpath($OutputFolderPath) . ReplaceWindowsFileNameSpecialCharacters($Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . '_' . $Mother->PatientTableRecord['NHSID'] . ' ' . date('d_m_Y') . '.pdf'),'F'); // $OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . ' ' . date('d_m_Y h_i_s', time()) . '.pdf','F');
回复2:
fopen(): remote host file access not supported, file://\MIA_TEST\HTDOCS\SharedFolder\MIA - Digital Post Natal RecordsFiona Appleton_1946546288 09_06_2015.pdf
PDF代码3:
// Worked
fopen($OutputFolderPath."Text.pdf", "w");
// Didn't work
$pdf->Output($OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . '_' . $Mother->PatientTableRecord['NHSID'] . ' ' . date('d_m_Y') . '.pdf','F'); // $OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . ' ' . date('d_m_Y h_i_s', time()) . '.pdf','F'
// Works with no PDF content inside
fopen($OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . '_' . $Mother->PatientTableRecord['NHSID'] . ' ' . date('d_m_Y') . '.pdf','F'); // $OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . ' ' . date('d_m_Y h_i_s', time()) . '.pdf','w');
响应 3:
fopen(file:////MIA_TEST/htdocs/SharedFolder/MIA - Digital Post Natal Records/Fiona Appleton_1946546288 09_06_2015.pdf): failed to open stream: No such file or directory
如果
//MIA_TEST/htdocs/SharedFolder
是一个有效的路径。保存 PDF 应该不会有任何问题。 PHP 无法找到您指定的路径。
尝试做一个简单的
fopen("//MIA_TEST/htdocs/SharedFolder/sample.txt", "w");
如果可行,那么您的问题就解决了。请确保路径正确。还要检查目标路径中是否有空格。
Output()
用下划线替换空格并删除特殊字符。您可能想确保这些事情的一切都是正确的。
http://www.tcpdf.org/doc/code/classTCPDF.html#a3d6dcb62298ec9d42e9125ee2f5b23a1
我发现我可以使用这个:
$savedOutput = file_get_contents('SavedOutput.pdf');
file_put_contents('newSavedOutput.pdf', $saveOutput);
我把PDF存到文件夹里,然后获取内容存到共享文件夹里