Saving File to Folder using PHP

107 views Asked by At

Few examples I've tried

// 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');

// Worked
$pdf->Output('C:/ISOSEC/PDFS/' . 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'

I'm trying to use the $OutputFolderPath

'$OutputFolderPath' Path:

//MIA-Test/htdocs/SharedFolder/MIA - Digital Post Natal Records/

Error:

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
1

There are 1 answers

1
PHP Worm... On BEST ANSWER

Use this :

$a = file_get_contents('Text.pdf');
file_put_contents('new_text.pdf', $a);