Page 1 of 1

fgets(STDIN) not working

Posted: Thu Jun 22, 2017 7:10 pm
by pizzipie
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

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()

Re: fgets(STDIN) not working

Posted: Fri Jun 23, 2017 10:05 am
by requinix
Are you running this from the command line or a browser? Has to be the command line.

Re: fgets(STDIN) not working

Posted: Fri Jun 23, 2017 11:09 am
by pizzipie
Yes, I am running it from the browser.

This statement doesn't work from the browser?

Guess I'll have to figure another way to do this.

Any hints on how to do this in the browser?

thanks, R

Re: fgets(STDIN) not working

Posted: Fri Jun 23, 2017 12:22 pm
by requinix
That code is neither made for nor intended to be run from a browser.

What's wrong with the command line?

Re: fgets(STDIN) not working

Posted: Sat Jun 24, 2017 11:16 am
by Christopher
pizzipie wrote:Yes, I am running it from the browser.

This statement doesn't work from the browser?
No
pizzipie wrote:Guess I'll have to figure another way to do this.

Any hints on how to do this in the browser?
Use a web form and get the values from $_POST.

The command line is also a fine option. Pass args and get the values from $argv:

See: http://php.net/manual/en/reserved.variables.php

Re: fgets(STDIN) not working

Posted: Mon Jun 26, 2017 1:27 pm
by pizzipie
[SOLVED]

Thank you "Site Admin".

I have created a cmd line app which works just fine.

I just think that with an app on the browser it is more elegant and easier to access. Prettier too.

Thanks again, all

R