Forum Moderators: coopster
I have a "template" .html file on a server lets say it's in the "template" folder under /public_html
I want to have a script copy that file to a different directory on the same server say "1234" under /public_html and also do this for as many folders as I tell it to.
example, I want to copy this .html file to 150 new folders starting off with folder number 5000
Can this be done and how hard would it be? I'd appreciate any help from anyone.
But, you might want to explain why you want the same file in 150 different directories. That doesn't sound like a good solution to whatever your problem is.
PHP knows something called 'include'
[php.net...]
and even though i have no idea what you're trying to accomplish, i'm still guessing that's a much better solution :-)
This should work although i haven't tested it.
Basically if I wanted to have a file the same ( atleast to start with ) for each customer, I figured by copying a template file into their corresponding directory and then editing it from there would be the best soluion. Anyone agree? Or am I missing some really cool php feature that would just make my life easier? :)
1. <html>
2. <head>
3. <title>PHP Copy template file</title>
4. </head>
5. <body>
6. <?php
7. $num_of_copies = 150;
8. $start_folder="500";
9. for($i = 0; $i < $num_of_copies; $i++)
10. {
11. $dest = "/public_html/".$startfolder.$i."template.html"
12. if(!copy("/public_html/template.html",$dest))
13. {
14. echo "File not copied to ".$dest;
15. }
16. }
17.?>
18. </table>
19. </body>
20. </html> And this is the result:
Parse error: syntax error, unexpected T_IF in /home/roguedog/public_html/template.php on line 12
I'm assuming it has something to do with the if statement?
Also on line 11 I think the .$startfolder should be .$start_folder am I correct?
Basically if I wanted to have a file the same ( atleast to start with ) for each customer, I figured by copying a template file into their corresponding directory and then editing it from there would be the best soluion.
well, you're talking about a template file here. copying the template file to 150 locations and then editing that template doesn't sound logical. If you don't want to use the same template over and over again, it kinda lost it's function. And if you do, a simple include (see link in previous post) would be the best solution.
about the error: it's because there is ; missing at the end of line 11
Warning: copy(/public_html/template.html): failed to open stream: No such file or directory in /home/roguedog/public_html/template.php on line 12
File not copied to /public_html/5000template.html
it just repeats based on the filename 5001template.html, 5002template.html and so on...
The include would work if nothing was changing within that template.html file but there is very specific customer info that will change and can't be included into the next template.html file if that makes any sense...maybe i'm thinking of it wrong...I dunno, so far it seems to be a straight forward task but I'm messing it up I guess. :(
I made those changes and I get a repeating error starting with:Warning: copy(/public_html/template.html): failed to open stream: No such file or directory in /home/roguedog/public_html/template.php on line 12
File not copied to /public_html/5000template.htmlit just repeats based on the filename 5001template.html, 5002template.html and so on...
That's because you don't have the right permissions [google.com]
The include would work if nothing was changing within that template.html file but there is very specific customer info that will change and can't be included into the next template.html file if that makes any sense...maybe i'm thinking of it wrong...I dunno, so far it seems to be a straight forward task but I'm messing it up I guess. :(