MTCCOMP
asked on
php script help
I have not done php.
I need a simple php script that will run in Linux or unix envr.
what I have:
10 xml files ( 1.xml, 2.xml ....)
in a folder on the web hosting server
the script will be run by some program everyday same time
what I want:
script that will change the file name every day in this way
for example
change 1.xml to main.xml today
then next day
change 2.xml to main.xml ( it need to know what it did yesterday)
....
then next day
change 10.xml to main.xml
then next day (back to)
change 1.xml to main.xml
I need a simple php script that will run in Linux or unix envr.
what I have:
10 xml files ( 1.xml, 2.xml ....)
in a folder on the web hosting server
the script will be run by some program everyday same time
what I want:
script that will change the file name every day in this way
for example
change 1.xml to main.xml today
then next day
change 2.xml to main.xml ( it need to know what it did yesterday)
....
then next day
change 10.xml to main.xml
then next day (back to)
change 1.xml to main.xml
ASKER
I have create some code, as I have never done the php, if someone check and suggest any thing.
<?php
$dirInUse = './InUse';
$dirMmain = './Mmain';
$dirAllFiles = './AllFiles';
$tempfilename = glob('./InUse/*.xml');
$filename = basename($tempfilename, ".xml");
//echo $filename;
//echo "<br/>";
$Ver = (int)$filename + 1;
//echo $Ver;
//echo "<br/>";
if ($Ver > 10) {
$Ver = 1;
}
//echo $Ver;
//echo "<br/>";
$newfilename = (string)$Ver . '.xml';
//echo "Output= {$newfilename}";
//echo "<br/>";
unlink('./InUse/*.xml');
copy($dirAllFiles & $newfilename, $dirInUse);
rename ($dirAllFiles & $newfilename, $dirMain & '/Main.xml');
?>
<?php
$dirInUse = './InUse';
$dirMmain = './Mmain';
$dirAllFiles = './AllFiles';
$tempfilename = glob('./InUse/*.xml');
$filename = basename($tempfilename, ".xml");
//echo $filename;
//echo "<br/>";
$Ver = (int)$filename + 1;
//echo $Ver;
//echo "<br/>";
if ($Ver > 10) {
$Ver = 1;
}
//echo $Ver;
//echo "<br/>";
$newfilename = (string)$Ver . '.xml';
//echo "Output= {$newfilename}";
//echo "<br/>";
unlink('./InUse/*.xml');
copy($dirAllFiles & $newfilename, $dirInUse);
rename ($dirAllFiles & $newfilename, $dirMain & '/Main.xml');
?>
If you're new to PHP this article will help you find your way to good learning resources and avoid all of the bad code examples that litter the internet.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
I think your design will be easier if you use a data base to hold the XML documents, or at least to hold the file names. If you want to give us the "high-level" view of the application, and tell us about the business rules you want to implement we may be able to help with a more mainstream design pattern.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
I think your design will be easier if you use a data base to hold the XML documents, or at least to hold the file names. If you want to give us the "high-level" view of the application, and tell us about the business rules you want to implement we may be able to help with a more mainstream design pattern.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for all the input
ASKER
After 3 post, i got one reply. By that time i have put the some code together which you said was good. How should i rate that "A".
"A" should be the default grade awarded unless the answer is deficient. An A grade means the solution provided is thorough and informative or is a link to information that answered the question. Any links that are posted will be accompanied by a summary of what can be found there and how it helps solve the problem.
"B" is the grade given for acceptable solutions, or a link to an acceptable solution. A B grade means the solution given lacked some information or required you to do a good amount of extra work to resolve the problem. When closing the question, the asker should explain why a B grade was awarded.
In my case it was accepatable solution"B" as, it did not give me the answer
but was pointing me to to read some php materail, which i have already done as i had post the code before the first reply.
"B" does not mean"uncooperative or unable to help you"
I have appricate you help in atleast respoinding therefore i gave teh B and 200 points.
"A" should be the default grade awarded unless the answer is deficient. An A grade means the solution provided is thorough and informative or is a link to information that answered the question. Any links that are posted will be accompanied by a summary of what can be found there and how it helps solve the problem.
"B" is the grade given for acceptable solutions, or a link to an acceptable solution. A B grade means the solution given lacked some information or required you to do a good amount of extra work to resolve the problem. When closing the question, the asker should explain why a B grade was awarded.
In my case it was accepatable solution"B" as, it did not give me the answer
but was pointing me to to read some php materail, which i have already done as i had post the code before the first reply.
"B" does not mean"uncooperative or unable to help you"
I have appricate you help in atleast respoinding therefore i gave teh B and 200 points.
ASKER
Server will have Three folders
InUse - Copy of the currently in use file without name change so it remeber which one was changed
Main - Copy of the Currently in use file with name change to Main.xml
AllFiles - Will have all the files (1.xml,2.xml....)
CODE:
FileName = Get file name from \inuse\1.xml
InUseVer = FileName (get file name without the extension)
InUseVer = InUseVar + 1
if( Inusevar > 10 ) then
InUseVer = 1
end if
FileName = InuseVar & ".xml"
Del \inuse\*.*
Copy \AllFiles\FileName \Inuse\Filename
Copy \AllFiles\FileName \Inuse\Main.xml