2015-06-09 85 views
1

我試圖將我的PDF文件保存到「共享文件夾」,我使用配置文件來設置「共享文件夾」,然後我只設置路徑PHP文件。生成TCPDF輸出到共享驅動器文件夾

但是它不會讓我保存了「共享文件夾」的路徑,它給我的錯誤:

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 

回答

0

我發現我可以用這個:

$savedOutput = file_get_contents('SavedOutput.pdf'); 
file_put_contents('newSavedOutput.pdf', $saveOutput); 

我的PDF保存到一個文件夾,然後獲取內容,並將其保存到共享文件夾

0

如果

//MIA_TEST/htdocs/SharedFolder 

是一個有效的路徑。您不應該在保存PDF時遇到任何問題。 PHP無法找到您指定的路徑。

嘗試做一個簡單的

fopen("//MIA_TEST/htdocs/SharedFolder/sample.txt", "w"); 

如果一切正常,你的問題就解決了。請確保路徑正確。另請檢查目標路徑中是否有空格。

Output() 

用下劃線替換空格並刪除特殊字符。你可能想確保一切都適合這些事情。

http://www.tcpdf.org/doc/code/classTCPDF.html#a3d6dcb62298ec9d42e9125ee2f5b23a1

+0

我可以」 t獲取絕對路徑,因爲它是給別人的,讓我可以訪問'共享驅動器(文件夾)',我必須將文件保存在其中。 –

+0

您可以指定提供給您的是什麼嗎? –

+0

在我的測試服務器上,我可以訪問所有內容。所以我不得不建立我自己的共享文件夾。但是,當我發送該項目時,只能通過我在代碼中完成的操作訪問共享驅動器。 - 在我的代碼中,我可以製作文件夾「MIA - 數字化產後記錄」,但由於某種原因在PDF輸出行中無法創建PDF - 文件夾結構的實際創建工作正常,這是該文件的創建似乎失敗,但與絕對路徑 –

相關問題