'Php not updating word document
I had created an automation system with php which takes information straight from a contact form on my website and fills in the information into a word template contract and sends me the contract with the filled in information.
After running the code this is error message
Warning: ZipArchive::close(): Failure to create temporary file: Permission denied i
how do I fix this?
if (!file_exists($folder))
{
mkdir($folder);
}
//Copy the Template file to the Result Directory
copy($template_file_name, $full_path);
// add calss Zip Archive
$zip_val = new ZipArchive;
$fill_1 = (string) $_POST["name_1"];
$fill_2 = (string) $_POST["surname_1"];
$fill_3 = (string) $_POST["name_2"];
$fill_4 = (string) $_POST["surname_2"];
$fill_5 = (string) $_POST["id_number_1"];
$fill_6 = (string) $_POST["id_number_2"];
$fill_7 = (string) $_POST["valofestate_1"];
$fill_8 = (string) $_POST["valofestate_2"];
//Docx file is nothing but a zip file. Open this Zip File
if($zip_val->open($full_path) == true)
{
// In the Open XML Wordprocessing format content is stored.
// In the document.xml file located in the word directory.
$key_file_name = 'word/document.xml';
$message = $zip_val->getFromName($key_file_name);
$timestamp = date('d-M-Y H:i:s');
// this data Replace the placeholders with actual values
$message = str_replace("token1", " $fill_1", $message);
$message = str_replace("token2", " $fill_2", $message);
$message = str_replace("Token3", " $fill_3", $message);
$message = str_replace("token4", " $fill_4", $message);
$message = str_replace("token5", " $fill_5", $message);
$message = str_replace("token6", " $fill_6", $message);
$message = str_replace("token7", " $fill_7", $message);
$message = str_replace("token8", " $fill_8", $message);
//Replace the content with the new content created above.
$zip_val->addFromString($key_file_name, $message);
$zip_val->close();
}
}
catch (Exception $exc)
{
$error_message = "Error creating the Word Document";
var_dump($exc);
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|