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


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


I need a php page in which I will say


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

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

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
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.
Vimal DMSenior Software EngineerCommented:

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

From novice to tech pro — start learning today.