How to Call feh from PHP

A

Anonymous

Guest
I am trying to create a slide show viewer which allows the user to
select from a list of people who are tagged in the photos and it then
displays a slide show of all pictures including any of these people.

I have created a screen in PHP which allows to select from a drop-down
list, queries the database and creates a list of photographs and writes
the list to a text file (I thought that would be the difficult bit!).

I can then run a terminal command
feh -f plist.txt -FD2 -d
that calls feh and uses the list to show a slide show.

The bit that I can't figure out is how to get PHP to trigger the slide
show.
shell_exec('feh -f plist.txt -FD2 -d');

does nothing. I also have a shell script, plist.sh which works from
command line, but
shell_exec('./plist.sh');
in PHP does nothing.

Any ideas? Do I need to use javascript or something to call it? Any
pointers much appreciated.

Mick
 
It's probably not in the correct location from your php script, you will probably have problems with permissions as well.

You could try moving the script to your web root folder and see if that works. But if you are showing the slides in a browser, you are better off changing the php script to do that instead of using shell_exec which could potentially lead to security issues.
 
I just tried moving it to my web root and it makes no difference, still does not display anything.
I was trying to use feh because it looked like the easy way to do it :) How can I do it within PHP? The code I have will generate the picture file paths, just need a way to display them as a slide show.
 
Can you explain what you have where, otherwise I'm going to be asking one question at a time :)

the line you have
Code:
shell_exec('./plist.sh');
means to look in the same directory, in which case both files (your php script and the plist.sh) would need to be in the same directory to work.

How is you script displaying the slide show?
 
OK I hold my pictures in digikam, which has a sqlite database and allows multiple tags and other things. What I want to do is take a copy of all of the pictures and the database on another machine and use that to provide a webpage for family that allows them to select one or more people and see a slide show of all pictures having tags of one or more of the people selected.

I have written some PHP which will create the drop down selection, allow the user to select people and use that to query the database and create a list of pictures. What I cannot do is display them.

Here is the code
Code:
<!DOCTYPE HTML> 
<html>
<head>
	<title>Tag Selection Screen</title>

<style>
label,a 
{
	font-family : Arial, Helvetica, sans-serif;
	font-size : 12px; 
}

</style>

<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
# now log on to the database
try {
	$db = new PDO('sqlite:/home/mick/Documents/Pictures/Album/digikam4.db');
	}
catch(PDOException $e)
    {
    echo $e->getMessage();
    }
?>
</head>

<body>
<h1>People Selection</h1>
<?php
	$set=0;
	if(isset($_POST['formSubmit'])) 
	{
		$set=1;
		$aPerson = $_POST['formPerson'];
		
		if(!isset($aPerson)) 
		{
			echo("<p>You selected zero people</p>\n");
		} 
		else 
		{
			$nPerson = count($aPerson);
			
			echo("<p>You selected $nPerson people: ");
			for($i=0; $i < $nPerson; $i++)
			{
				echo($aPerson[$i] . " ");
			}
			echo("</p>");
		}
	}

$query = "select '...' id, ' - Select Names -' name
union
SELECT id id, name name FROM tags t where t.id in (select id from tagstree tt where tt.pid = 22) 
order by t.name";
?>

<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
	<label for='formPerson[]'>Select the people to include:</label><br>
	<select multiple="multiple" name="formPerson[]">
				
		<?php 
		foreach ($db->query($query) as $row){//Array of records stored in $row
			echo "<option value=$row[id]>$row[name]</option>";}
		echo "</select>";// Closing of list box
		?>

	<input type="submit" name="formSubmit" value="Submit" >
</form>

<?php	
echo '<br>set = ',$set;
echo '<br>';
if($set=1)
{
	for($i=0; $i<$nPerson; $i++) 
	{
		echo($aPerson[$i] . " ");
	}
echo 'Just before the list of pics';

$list = implode(',', $aPerson);

	$pic_query='SELECT a.relativePath || "/" || i.name pic
from 
Images i,
ImageTags it,
Albums a
where 
it.imageid = i.id
and it.tagid in ('.$list.
') and i.album = a.id
order by a.relativePath, i.name'	;


echo $pic_query;
echo '<br>set = ',$set;
echo ' after set = <br>';

try {
$result = $db->query($pic_query);
	}
catch(PDOException $e)
    {
    echo $e->getMessage();
    echo $e;
    }

//echo '<br>result = ',  $result;
echo 'Current script owner: ' . get_current_user().'<br>';
$d = '/home/mick/Documents/Pictures/Album';
$plist = fopen("plist.txt", "w") or die("Unable to open file!");
foreach($result as $row)
	{
//		echo($row['pic'] . " ");    
		$cmd = 'feh -f '.$d.$row['pic'].' -F -D 2.0 -S filename -d -Y<br>';
		system($cmd);
		fwrite($plist, $d.$row['pic']."\n");
		echo $cmd;
	}
	fclose($plist);
	
	echo 'pwd = '.shell_exec('pwd').'<br>';
//	$ret = shell_exec('./usr/bin/feh -f /home/mick/www/test/plist.txt -FD2 -d');
	
//	$ret = 
	shell_exec('/home/mick/www/test/plist.sh');
	echo '<br>shell_exec should have run';
//	echo 'ret = '.$ret;
}
?>

</body>
</html>
I'm sure there are lot of things wrong with it but this is what I have at the moment.

Many thanks for your help.
Mick
 
Back
Top