Jump to content

mpg

Members
  • Posts

    18
  • Joined

  • Last visited

Contact Methods

  • Website URL
    mpgradio.ca

Profile Information

mpg's Achievements

Member

Member (2/5)

0

Reputation

  1. DOnt laugh this is the best i can come up with. <?php $total_receivables = file('balance.txt'); echo "Reciveables $" . array_sum($total_receivables) . "\n"; echo ' | '; $total_expenses = file('ebalance.txt'); echo "Expenses $" . array_sum($total_expenses) . "\n"; $diff = array_sum($total_receivables) - array_sum($total_expenses); echo "$diff"; ?> No I didnt but now that you mention it everything works out....DUH.
  2. DOnt laugh this is the best i can come up with. <?php $total_receivables = file('balance.txt'); echo "Reciveables $" . array_sum($total_receivables) . "\n"; echo ' | '; $total_expenses = file('ebalance.txt'); echo "Expenses $" . array_sum($total_expenses) . "\n"; $diff = $total_receivables - $total_expenses; echo "$diff"; ?>
  3. I wanted to know how to take both those files and subtract the difference. Stuck there at the moment.
  4. just adding the total of either one. <?php $lines = file('balance.txt'); echo "Reciveables $" . array_sum($lines) . "\n"; ?>
  5. I Have two txt files I need to read both subtract the difference. So subtract eexpense from balance and print result. Cant see to figure it….probably simple, perhaps someone can help. I have attached both...balance.txt So if balance.txt is 330 and eexpense.txt is 60 the result is 270 eexpense.txt
  6. Ok here is a test page if this helps. Must be something im missing in part of foreach...just not sure what.. <?php session_start(); require('rotationswitch.php'); $stationlist = stationlist(); ?> <?php ob_start();?> <html> <head> <!DOCTYPE HTML> <html> <head> <title>MPG Radio - Music for Review</title> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> <link rel="stylesheet" href="./assets/css/mainstation.css" /> </head> <body bgcolor="#b23c30"> <div style="background-color:white;color:black;padding:20px;"> <center><h2>Moving Selected Music</h2> <h3>Music is being moved, just a moment.</h3> </center><br> <?php //set folder to read from $dir = ('C:\\EZSTREAM\\SMASH2\\'); $iterator = new RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $filename => $fileInfo) { if ($fileInfo->isDir()) { //loop through all files $moved = false; foreach(stationlist() as $stationname => $path) { if($stationname !== $_POST['station']) continue; $source = $dir . $filename; $destination = $path . "\\" . $filename; echo "<h2><center>Moving from this Source: $source</h2></center><br />"; echo "<h2><center>To this Destination: $destination</h2></center><br />"; rename($source, $destination); } } } echo "files dont move from <b>source</b> to <b>destination</b><br>"; echo "<a href='filter.php'>return for now and lets try again...</a>"; ?> </body> </html> <?php ob_flush(); ?>
  7. Ah crap that worked for got to close, at least the page loads but still doesn't move the file selected......humm
  8. Whoops for got to do that.... What I have...hope someone can help, sorry about the messy code ill clean it up. The idea is to filter a file by first part of the filename dave mohan - song.mp3 and move only that to the target directory. //LIST FILES WITH DROPDOWN SELECTOR <?php class IgnorePathFilterIterator extends \FilterIterator { public function accept(): bool { $current = strtolower(parent::current()->getFilename()); return !in_array($current, ['thumbs.db', 'tag', 'playlist.m3u']); } } $dir = 'C:\\EZSTREAM\\smash2\\'; //$dir = '.'; $rdi = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS); $rii = new \RecursiveIteratorIterator($rdi, \RecursiveIteratorIterator::CHILD_FIRST); $iterator = new IgnorePathFilterIterator($rii); foreach($iterator as $path => $info) { if ($info->isDir()) { echo "DIR $path<br />\n"; } else { echo "FILE $path<br />\n"; } } ?> <hr> //My thingy filtering out only the dave mohan mp3 files<br> <?php $dir = ('C:\\EZSTREAM\\SMASH2\\'); $iterator = new RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $filename => $fileInfo) { if ($fileInfo->isDir()) { //probally still want to use this somewhere //$ignore = Array(".", "..", "Thumbs.db" , "tag", "playlist.m3u"); } else { if (preg_match("/(\A[Dave Mohan].*.mp3)/", $fileInfo->getFileName())) { //echo $filename . '<br/>'; echo "<a href='?file=".$filename."'>$filename</a> <form action=\"removesmash2.php\" style=\"display: inline\" method=\"post\"><input type=\"hidden\" name=\"filename\" value=\"".htmlentities($curfile)."\" />"; pickstation(); echo " <input style=\"padding: 1.26em; line-height: 0.899em; height: auto\" type=\"submit\" value=\"move\" /></form> (move this song into the archive or trash)</br>\n <hr> "; } } } ?> //My problem is the removesmash2.php below throws and error I cant seem to solve... <?php //set folder to read from //$dirname = "C:\\EZSTREAM\\SMASH2\\"; $dir = ('C:\\EZSTREAM\\SMASH2\\'); $iterator = new RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $filename => $fileInfo) { if ($fileInfo->isDir()) { //read files in folder //$files = scandir($dir); //ignore hidden files //$ignore = Array(".", "..", "Thumbs.db", "Playlist.m3u"); //loop through all files $moved = false; //foreach($files as $filename){ //if($filename !== $_POST['filename']) continue; foreach(stationlist() as $stationname => $path) { if($stationname !== $_POST['station']) continue; $source = $dir . $filename; $destination = $path . "\\" . $filename; echo "<h2><center>Moving from this Source: $source</h2></center><br />"; echo "<h2><center>To this Destination: $destination</h2></center><br />"; rename($source, $destination); } } ?> // for reference path selector (dropdown) looks like this <?php function stationlist() { return [ //"REASSIGN" => "C:\\XAMPP\\HTDOCS\\MPG\\RADIO\\BSP\\ASSIGNMENT", "Select Destination" => "/", //"Select Destination" => "C:\\XAMPP\\HTDOCS\\MPGRADIO\\BSP\\DAVEMOHAN", "BACKUP" => "C:\\XAMPP\\HTDOCS\\MPGRADIO\\BSP\\DAVEMOHAN\\BACKUP", "SMASH1" => "C:\\EZSTREAM\\SMASH1", "SMASH2" => "C:\\EZSTREAM\\SMASH2", "Trash it" => "C:\\BACKUP\\TRASH\\SONGS\\DAVEMOHAN", ]; } ?> Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\mpgradio\bsp\davemohan\removesmash2.php on line 99
  9. What I have...hope someone can help, sorry about the messy code ill clean it up. The idea is to filter a file by first part of the filename dave mohan - song.mp3 and move only that to the target directory. //LIST FILES WITH DROPDOWN SELECTOR <?php class IgnorePathFilterIterator extends \FilterIterator { public function accept(): bool { $current = strtolower(parent::current()->getFilename()); return !in_array($current, ['thumbs.db', 'tag', 'playlist.m3u']); } } $dir = 'C:\\EZSTREAM\\smash2\\'; //$dir = '.'; $rdi = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS); $rii = new \RecursiveIteratorIterator($rdi, \RecursiveIteratorIterator::CHILD_FIRST); $iterator = new IgnorePathFilterIterator($rii); foreach($iterator as $path => $info) { if ($info->isDir()) { echo "DIR $path<br />\n"; } else { echo "FILE $path<br />\n"; } } ?> <hr> //My thingy filtering out only the dave mohan mp3 files<br> <?php $dir = ('C:\\EZSTREAM\\SMASH2\\'); $iterator = new RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $filename => $fileInfo) { if ($fileInfo->isDir()) { //probally still want to use this somewhere //$ignore = Array(".", "..", "Thumbs.db" , "tag", "playlist.m3u"); } else { if (preg_match("/(\A[Dave Mohan].*.mp3)/", $fileInfo->getFileName())) { //echo $filename . '<br/>'; echo "<a href='?file=".$filename."'>$filename</a> <form action=\"removesmash2.php\" style=\"display: inline\" method=\"post\"><input type=\"hidden\" name=\"filename\" value=\"".htmlentities($curfile)."\" />"; pickstation(); echo " <input style=\"padding: 1.26em; line-height: 0.899em; height: auto\" type=\"submit\" value=\"move\" /></form> (move this song into the archive or trash)</br>\n <hr> "; } } } ?> //My problem is the removesmash2.php below throws and error I cant seem to solve... <?php //set folder to read from //$dirname = "C:\\EZSTREAM\\SMASH2\\"; $dir = ('C:\\EZSTREAM\\SMASH2\\'); $iterator = new RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $filename => $fileInfo) { if ($fileInfo->isDir()) { //read files in folder //$files = scandir($dir); //ignore hidden files //$ignore = Array(".", "..", "Thumbs.db", "Playlist.m3u"); //loop through all files $moved = false; //foreach($files as $filename){ //if($filename !== $_POST['filename']) continue; foreach(stationlist() as $stationname => $path) { if($stationname !== $_POST['station']) continue; $source = $dir . $filename; $destination = $path . "\\" . $filename; echo "<h2><center>Moving from this Source: $source</h2></center><br />"; echo "<h2><center>To this Destination: $destination</h2></center><br />"; rename($source, $destination); } } ?> // for reference path selector (dropdown) looks like this <?php function stationlist() { return [ //"REASSIGN" => "C:\\XAMPP\\HTDOCS\\MPG\\RADIO\\BSP\\ASSIGNMENT", "Select Destination" => "/", //"Select Destination" => "C:\\XAMPP\\HTDOCS\\MPGRADIO\\BSP\\DAVEMOHAN", "BACKUP" => "C:\\XAMPP\\HTDOCS\\MPGRADIO\\BSP\\DAVEMOHAN\\BACKUP", "SMASH1" => "C:\\EZSTREAM\\SMASH1", "SMASH2" => "C:\\EZSTREAM\\SMASH2", "Trash it" => "C:\\BACKUP\\TRASH\\SONGS\\DAVEMOHAN", ]; } ?>
  10. <?php function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object); } } reset($objects); rmdir($dir); } } $filesToKeep = array( 'tokenset.php', 'index.php', 'done.php', 'count.php', 'tokenmaster', 'start' ); $dirList = glob('*'); foreach ($dirList as $file) { if (! in_array($file, $filesToKeep)) { if (is_dir($file)) { rrmdir($file); } else { unlink($file); }//END IF }//END IF }//END FOREACH LOOP ?> Thought I might show the solution that was used....
  11. Ok then that's a start, i'm going to narrow that down from removing args.
  12. Ok I'm clearly not call the removeDirectory function correctly and the $leave_files function is also not done correctly. There are no errors though. Ill keep at it and come up with something better.....Thank you. 😀
  13. <?php $leave_files = array('done.php', 'done2.php', 'index.php', 'tokenset.php', 'tokenmaster'); function removeDirectory($path) { $files = glob($path . '/*'); foreach ($files as $file) { is_dir($file) ? removeDirectory($file, $leave_files) : unlink($file); } rmdir($path); return; } ?> Last item on this, I'm trying to remove the directories (and files in each) in the root folder, but leave selected files and folders using $leave_files function, I must be doing something wrong any advise would be great.
  14. <?php // get the last created/modified directory $path = "./"; $latest_ctime = 0; $latest_dir = ''; $d = dir($path); while (false !== ($entry = $d->read())) { $filepath = "{$path}/{$entry}"; if(is_dir($filepath) && filectime($filepath) > $latest_ctime) { $latest_ctime = filectime($filepath); $latest_dir = $entry; } } //end loop //echo $latest_dir; //echo "<a href=$latest_dir $latest_file><button>"."continue</button></a><br>"; echo "<a href='$latest_dir/tokendone$name.php'><button>"."continue</button></a><br>"; ?> Ok thank you with a little adjustment i have this part working now...............so thank you again. hope im not asking to many questions, I tend to do that.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.