fgets(STDIN) not working
Posted: Thu Jun 22, 2017 7:10 pm
I have a function in which I type in a choice of one of a list of directories produced by scandir() for further processing.
There are two problems;
1. The code "$photoFile = trim(fgets(STDIN));" is skipped over and not working.
2. In this echo statement echo "\nEnter a Directory Name to Process From List \n\n"; the 'line returns don't work.
The out put is all on one line As:
List of Possible Source Files 102CANON CANONMSC Enter a Directory Name to Process From List line 121
Thanks in advance for your help with this,
R
There are two problems;
1. The code "$photoFile = trim(fgets(STDIN));" is skipped over and not working.
2. In this echo statement echo "\nEnter a Directory Name to Process From List \n\n"; the 'line returns don't work.
The out put is all on one line As:
List of Possible Source Files 102CANON CANONMSC Enter a Directory Name to Process From List line 121
Thanks in advance for your help with this,
R
Code: Select all
// =============== function Get Photo List() ===============
function getPhotoList() {
$dcimDir=getcwd()."/DCIM"; // change dir to where the photo directories are
$items=scandir($dcimDir);
echo "\nList of Possible Source Files\n\n";
foreach($items as $item) {
if($item != "." && $item != "..") {
echo $item."\n";
}
}
echo "\nEnter a Directory Name to Process From List \n\n"; // change dir to where the photos are
$photoFile = trim(fgets(STDIN)); // reads one line from STDIN we want correct file as source
$imageDir=getcwd()."/DCIM/". $photoFile;
echo "imgDir ".$imageDir."\n";
chdir($imageDir); // this is where the photos are
exit('line 127');
// ====== Store Photos To Desktop, VB-share and Pictures =====================
$processDate=date("YMd-G:i_");
$transDir=$desktop."/".$processDate."TransFile_".$photoFile; // Temporary Storage
mkdir($transDir);
$src=getcwd(); // ~/Desktop/photso
$cmd= "rsync -avz --dry-run ".$src." ".$transDir; // From Photo Source to Transfer Directory
echo shell_exec($cmd); // Store Photos in Transfer Directory on Desktop
} // end getPhotoList()