•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 392,076 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,034 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2333 | Replies: 2
![]() |
•
•
Join Date: Aug 2006
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
I have an e-commerce website and I am trying to have a webpage create a .doc or .rtf document to print labels based on the customers' addresses in a mysql database.
For this reason, I need to create a document based on a labels template.
I have saved the labels template as whslabels.rtf on the website, and on every label I have written "Address1", "Address2", "Address3", ... then I have the mentioned webpage do a str_replace replacing the "Address..." words with the customer's address, and then save this to a new file named "newlabels6.rtf".
[php]
[code]
$template_file = "whslabels.rtf";
$handle = fopen($template_file , "r");
$contents = fread($handle, filesize($template_file));
$original= array("Address1", "Address2");
$new = array("pizza", "beer");
$newphrase = str_replace($original, $new, $contents);
$handle2 = fopen("newlabel6.rtf" , "w");
fwrite ( $handle2 ,$newcontents);
fclose ($handle);
fclose($handle2);
[code]
[php]
but when I go to open the new .rtf file it doesn't seem to able to open it. The exact error I get is "The document file or path is not valid...."
What am I doing wrong?
For this reason, I need to create a document based on a labels template.
I have saved the labels template as whslabels.rtf on the website, and on every label I have written "Address1", "Address2", "Address3", ... then I have the mentioned webpage do a str_replace replacing the "Address..." words with the customer's address, and then save this to a new file named "newlabels6.rtf".
[php]
[code]
$template_file = "whslabels.rtf";
$handle = fopen($template_file , "r");
$contents = fread($handle, filesize($template_file));
$original= array("Address1", "Address2");
$new = array("pizza", "beer");
$newphrase = str_replace($original, $new, $contents);
$handle2 = fopen("newlabel6.rtf" , "w");
fwrite ( $handle2 ,$newcontents);
fclose ($handle);
fclose($handle2);
[code]
[php]
but when I go to open the new .rtf file it doesn't seem to able to open it. The exact error I get is "The document file or path is not valid...."
What am I doing wrong?
•
•
Join Date: Jul 2004
Location: North East Indiana
Posts: 491
Reputation:
Rep Power: 5
Solved Threads: 20
Are you writing plain text to a rich text file? That may not be the source of your problem, but it could be the source of another problem later.
I'd double check my paths and capitolzation, my quick look at your code segment didn't pick up anything immediately wrong.
One more thing, you only need to use either [ code ] or [ php ] tags, not both. The reason it failed to display properly is because you didn't turn them off (using [ /code ] or [ /php ]). BBCode like this takes a bit to get used to.
I'd double check my paths and capitolzation, my quick look at your code segment didn't pick up anything immediately wrong.
One more thing, you only need to use either [ code ] or [ php ] tags, not both. The reason it failed to display properly is because you didn't turn them off (using [ /code ] or [ /php ]). BBCode like this takes a bit to get used to.
www.uncreativelabs.net
Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
•
•
Join Date: Aug 2006
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
$template_file = "whslabels.rtf";
$handle = fopen($template_file , "r");
$contents = fread($handle, filesize($template_file));
$original= array("Address1", "Address2");
$new = array("Here is address one", "Here is address 2");
$newphrase = str_replace($original, $new, $contents);
$handle2 = fopen("newlabel6.rtf" , "w");
fwrite ( $handle2 ,$newcontents);
fclose ($handle);
fclose($handle2);Basically the template is a typical sheet of 21 labels made with Word, and originally saved as a .dot file. The addresses are made up in HTML by the php page, but instead of displaying the on the screen is trying to subsitute address 1 with lets say:
[html]
Mr John Smith<BR>
Flat 12, 42 Piccdilly Circus<BR>
W1<BR>
London<BR>
UK
[/html]
I have never done this before, and that is the only thing I could think of to reach my objective: having a page of lables ready to print with the address of the day's customers' orders.
The .dot file has originally Address1, Address2, Address3, ... where the addresses will go.
but when I go to open the new .rtf file it doesn't seem to able to open it. The exact error I get is "The document file or path is not valid...."
What am I doing wrong?[/quote]
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- Microsoft Word abnormal termination (Windows Software)
- How we open a ms word document file with php? (PHP)
- A suitable Word Template (ASP.NET)
- 5 Years Experiance In the PHP+MYSQL language and DB (Post your Resume)
- PHP .tpl format template help! URGENT! (PHP)
Other Threads in the PHP Forum
- Previous Thread: Using HTML tags in PHP code
- Next Thread: failed to create stream: HTTP wrapper does not support writeable connections


Linear Mode