php

[php]

<?php $file="sum.docx";(sum.docx file in www folder sum.docx contains add a and b) header("Content-Type:application/.docx"); header("Conent-Length" . filesize($file)); header("Content-Disposition:attachment";filename=sum.docx"); $content=file_get_contents($file); $string=str_replace("add","sub",$content); $fp=fopen($file,"w+"); fwrite($fp,$string); fclose($fp); echo file_get_contents($file); ?>

[/php]
The str_replace function was worked for ".Txt: files.But for .docx files the string was not replaced.i.e the contents of the file were not changed after string replacement.

something is wrong with header(“Content-Disposition:attachment”;filename=sum.docx");, i think its supposed to be

header(“Content-Disposition:attachment”);
$filename=“sum.docx”;

LOL, yes, a missing space before the “;”…

Also, sometimes I have found that you can not replace inside of a .DOCX file. Something to do with revision numbers or formatting… But, I bet the space was the problem…

Almost valid points above, but not in the case of what you are trying to achieve. Your line is nigh on fully correct bar the extra speech marks before the semicolon.

[php]
header(‘Content-Disposition:attachment; filename="’.$file.’"’);[/php]

Note the use of concatenation with ‘.$file.’ to use the previously created variable with the filename, rather than writing the same string twice. I’ve also wrapped the filename in quotes (with different quotation marks around the whole statement). Just changing your line to the above should be you sorted.

Sponsor our Newsletter | Privacy Policy | Terms of Service