Need to open files under specific names through PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
isgur513
Forum Newbie
Posts: 3
Joined: Fri Mar 14, 2008 12:28 pm

Need to open files under specific names through PHP

Post by isgur513 »

Hi all,

I currently have an html form that is used to register devices on my network. When someone goes to this form and puts in the MAC address, once they hit submit, two files must be created in the directory. A 'mac.cfg' and a 'mac-registration.cfg' (where mac=the mac address of the device). How would I implement this code so that I can open these files under these names and insert the information into it?

Thanks in advance,
Matt
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Re: Need to open files under specific names through PHP

Post by miro_igov »

Code: Select all

$fp = fopen('mac.cfg','w');
fwrite($fp, $the_info);
fclose($fp);
Same for the other file.

This sounds like VoIP phone configurator, something i worked on before. Are you working for TierZero ?
isgur513
Forum Newbie
Posts: 3
Joined: Fri Mar 14, 2008 12:28 pm

Re: Need to open files under specific names through PHP

Post by isgur513 »

Yes, this is for Polycom VOIP phone registration. Each phone needs two files to operate. Say I have a phone with MAC address of 0004f2151809, I need to create two files: (1)'0004f2151809.cfg' (2)'0004f2151809-registration.cfg'

How would I create a code to open these files for each individual polycom phone?

Thanks,
Matt
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Re: Need to open files under specific names through PHP

Post by miro_igov »

:) i knew it is the polycom devices. Actually the -registration.cfg is not important, however there are many details in the cfg file that you should have defined before to create these files.

First you should know all the mac addresses you have in the network and insert them in a HTML form, then submit it, process the entries in a loop and with fopen / fwrite / fclose generate file for each device.

You can set a variable and place the the configuration template inside. Take a look in the php manual for the function sprintf() to understand how to change the config values for every device.
Post Reply