Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

php script help

Posted on 2013-12-03
8
Medium Priority
?
525 Views
Last Modified: 2013-12-09
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
0
Comment
Question by:MTCCOMP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 

Author Comment

by:MTCCOMP
ID: 39693320
Some thing like this:


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
0
 

Author Comment

by:MTCCOMP
ID: 39693859
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');


?>
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39694036
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.
http://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.
0
Not sure which OpenStack Certification to get?

So you’ve realized you might want to get certified in OpenStack, but you’re not sure what the benefits might be or even which one you should take. You know there are several certification courses you can choose from, but how do you know which one is right for you?

 

Accepted Solution

by:
MTCCOMP earned 0 total points
ID: 39694587
Thanks for replay, I was reading lot on the internet since i post the Question.

Overview of the problem is the Client has Application, whcih use RSS feed xml file. Which is picked up from the web folder on hosting site (dodday).  Which work Ok.

Problem is that Custom xml Feed changes/rotate every 35 days ( 35 xml file, one for each day, then loop back). These 35 file  do get change once in while but the keep rotating every day.

Current they were changing the file each day manually, I was trying to make is automate.
If they create 35 file, put in one folder and system automatcally pick one file and rename and put in the folder when the system will pickup the file.

I have not use php, but what was used at the web hosting site.

There what i have created from what i have leard today (searching).  And it is WORKING now. I like it if one of the expert polish the code or give any input.


<?php

$dirInUse = './InUse';  // to know what last file was use
$dirMain = './Main/';   // Rename & copy curret file in use, as program will pick from here
$dirAllFiles = './AllFiles/';  // location of all 35 files

$tempfilename = glob('./InUse/*.xml');

$filename  = basename($tempfilename[0], ".xml");

$Ver = (int)$filename + 1;
if ($Ver > 35) {
$Ver = 1;
}

$newfilename = (string)$Ver . '.xml';

unlink($tempfilename[0]);

copy ($dirAllFiles . $newfilename, $dirInUse.'/'.$newfilename);
copy ($dirAllFiles . $newfilename, $dirMain .'Main.xml');

?>
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 800 total points
ID: 39695219
I wouldn't change a thing if it's working the way you want.  It looks fine to me.  Some day you may find that you want an abstraction layer between the numeric name and some kind of topical information.  When that time comes, you will want to use a data base.  But for now this is exactly what any professional programmer would do.

Best regards, ~Ray
0
 

Author Closing Comment

by:MTCCOMP
ID: 39705697
Thanks for all the input
0
 

Author Comment

by:MTCCOMP
ID: 39707752
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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question