how to copy content of one file into another by using php

hi,

on the server i have a file run.bat and then i have multiple template files

1001.scp
1002.scp
1003.scp

I need a php page in which I will say

http://server/modifybatchfile.php?template=1001

once this URL is executed then the contents of 1001.scp should be copied to run.bat

this is a very crude solution for a problem that I am facing but once i have this ready I will ask for more deeper questions

right now I just need to ensure that copying on the URL action works perfectly

thanks
-anshu
anshumaEngineeringAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
You might want to reconsider the security implications of modifying the contents of a file on the server on the basis of a GET request.  What if you wanted template=1001, but I sent along a request with template=1002 or worse, something else?  Your run.bat file could be overwritten, and you probably don't want that risk keeping you awake at night!

That said, you can copy files by using
file_put_contents('run.bat', file_get_contents('1001.scp'));

Open in new window

You can find the contents of the template= URL parameter in the $_GET variable.

If you're new to PHP and want some good learning resources, this article can help.
http://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
anshumaEngineeringAuthor Commented:
yes that was my concern, I need to plan for locking etc. I am making a simple web based command caller that calls commands on the server.

in a concurrent scenario when multiple systems can send URL's then this can be a problem

I was thinking of handling this by creating a queue table in a database and using some status flags etc

Do you have any other ideas
0
Ray PaseurCommented:
You might consider checking the IP address of the request.  If you're always coming from a set of predictable IP addresses, you can just ignore requests from other IP addresses.  The PHP environmental variables almost always allow you to discern this via $_SERVER['REMOTE_ADDR'].

It might be easiest to lock this, or organize it into transactions, if you use a database to collect the requests.  Then you would also have a record of the requests with timestamps, etc.
0
Vimal DMSenior Software EngineerCommented:
Hi,

Point 1:
Set the URL to be accessed only by a specific IP in .htaccess

Point 2:
Anybody can upload the .scp file to the location
0
anshumaEngineeringAuthor Commented:
thank you experts , have you created an application like this before based on database to create quueues of request. Some kind of help /architecture suggestions will be great. I can create a new thread for this if you want
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.