fgets(STDIN) not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pizzipie
Forum Commoner
Posts: 87
Joined: Wed Feb 10, 2010 10:59 pm
Location: Hayden. ID

fgets(STDIN) not working

Post 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()
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: fgets(STDIN) not working

Post by requinix »

Are you running this from the command line or a browser? Has to be the command line.
pizzipie
Forum Commoner
Posts: 87
Joined: Wed Feb 10, 2010 10:59 pm
Location: Hayden. ID

Re: fgets(STDIN) not working

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: fgets(STDIN) not working

Post by requinix »

That code is neither made for nor intended to be run from a browser.

What's wrong with the command line?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: fgets(STDIN) not working

Post 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
(#10850)
pizzipie
Forum Commoner
Posts: 87
Joined: Wed Feb 10, 2010 10:59 pm
Location: Hayden. ID

Re: fgets(STDIN) not working

Post 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
Post Reply