0

Hi I have to develop a code for file configuration in PHP.
My basic text file is stored in C:\abc
my text file name format is Mobile#_Code.request
Example: 923135470808_9033.request
Now I want to read code 9033 from the name of text file which always be there after _ and before .request
After getting code I will get data from MySQL DB and want to put this result in the form of message in the text file like "Hi 9033 your remaining balance is 50USD"
Now after putting message in same file I want to rename the file name as 923135470808_9033.done
means request changes in done.

please guide me.
Thanks

Attachments
Hi 9033 your balnace is 50USD
2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by ayesha789
0

I cant understand this by you
I have written this code for this but have some problems

<?php
include("config.php");
$dirname = "./abc";
$dir = opendir($dirname);
while(false != ($file = readdir($dir)))
{
if(($file != ".") and ($file != ".."))
{
echo("$file <br />");
$fileN = basename("./abc/$file", ".request.txt"); // $file is set to "index"
echo $fileN;
echo "<br />";
echo $Code=substr($fileN,13);
echo "<br />";
$result = mysql_query("SELECT Code,BaseAmount from lims_payment Where Code='$Code'");
$row = mysql_fetch_array($result);
echo $sms="Your cheque amount of " . $row[1] . " is ready in Regional office";
 $file2= fopen("./abc/$file","w") or die ("Error opening file in write mode!");    
fputs($file2,$sms); 
fclose($file2) or die ("Error closing file!"); 
//rename("./abc/$file", "./abc/1234.txt");
}
}

?>

Now I want to rename as written in step 5 in my attached immage any one guide how to rename part of file.

0

How I can change 923135470808_9033.request test file name to 923135470808_9033.done using PHP Code.

0

my problem solved i used string replace for renaming file name after puting text in it

0

its solved

<?php
include("config.php");
$dirname = "./abc";
$dir = opendir($dirname);
while(false != ($file = readdir($dir)))
{
if(($file != ".") and ($file != "..") and (substr($file,18)=="request") )
{
$fileN = basename("./abc/$file", ".request"); // $file is set to "index"
echo $fileN;
echo "<br />";
echo $Code=substr($fileN,13);
echo "<br />";
$r = mysql_query("SELECT Code from lims_payment Where Code='$Code'");
$num_rows = mysql_num_rows($r);
if($num_rows > 0)
{
$result = mysql_query("SELECT SiteId,Year(DurationS),pDate,cDate,Reasons from lims_payment Where Code='$Code' Order by DurationS DESC");
$row = mysql_fetch_array($result);

echo $sms="SiteId: " . $row[0] . "   Year: " . $row[1] . "   Processed Date: " . $row[2] . "   Cheque Issued Date: " . $row[3] . "   Status: " . $row[4] . "";
 $file2= fopen("./abc/$file","w") or die ("Error opening file in write mode!");    
fputs($file2,$sms); 
fclose($file2) or die ("Error closing file!");
//rename file name
$doneN = str_replace("request", "done", $file);
echo $doneN;
rename("./abc/$file", "./abc/$doneN");
}
else
{
$sms = "Please contact Yasin Zakir 03135565656 Or Ehasn Bari 03125604933 for Further Help.";
 $file2= fopen("./abc/$file","w") or die ("Error opening file in write mode!");    
fputs($file2,$sms); 
fclose($file2) or die ("Error closing file!");
//rename file name
$doneN = str_replace("request", "done", $file);
echo $doneN;
rename("./abc/$file", "./abc/$doneN");
}

}
}

?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.