Forum Moderators: coopster

Message Too Old, No Replies

Need help ( beware noob here )

         

RogueDogg

8:22 am on May 17, 2006 (gmt 0)

10+ Year Member



What I was wondering is this:

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.

siMKin

9:39 am on May 17, 2006 (gmt 0)

10+ Year Member



what you need is a combination of these two:
[php.net...]
[php.net...]

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 :-)

eelixduppy

11:06 am on May 17, 2006 (gmt 0)



It would be something like this:
$num_of_copies = 150;
$start_folder="500";
for($i = 0; $i < $num_of_copies; $i++)
{
$dest = "/public_html/".$startfolder.$i."template.html"
if(!copy("/public_html/template.html",$dest))
{
echo "File not copied to ".$dest;
}
}

This should work although i haven't tested it.

RogueDogg

1:59 pm on May 17, 2006 (gmt 0)

10+ Year Member



Well thank you 2 for your rapid help. I will try to figure out from what you have given me for information if it will work for me or not.

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? :)

RogueDogg

2:10 pm on May 17, 2006 (gmt 0)

10+ Year Member



Well this is basically what I tried:

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?

siMKin

2:44 pm on May 17, 2006 (gmt 0)

10+ Year Member



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

wheelie34

2:45 pm on May 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would hazard a guess its the naming as you stated of $start_folder both have to be the same change it and try it.

add ; to the end of line 11, missed that myself

RogueDogg

3:01 pm on May 17, 2006 (gmt 0)

10+ Year Member



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.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. :(

siMKin

6:28 am on May 19, 2006 (gmt 0)

10+ Year Member



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.html

it 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. :(

If the stuff that changes is only about content and not about layout, there is still no problem at all. Just define it as variables and you can reuse the template 150 times (or even 150 million)