LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-15-2003, 09:25 AM   #1
Spooky
Member
 
Registered: Dec 2002
Location: Portugal
Distribution: Fedora Core 5
Posts: 82

Rep: Reputation: 15
Shell commands in HTML?


I need to create a HTML site with some kind of way to execute a normal shell command ... so that i can create another .html file...

Basicaly i need something that reads and creates a HREF link to the files that are present in a dir when i like to have acess to them... i already do this but i have to enter into my shell acount and execute this command :
------------------------------------------------------------------------------------------------
echo "<HTML><BODY>" > index.html; for i in `ls`; do echo "<a HREF="$i">$i</a><br>">> index.html; done; echo "</BODY></HTML>" >> index.html
------------------------------------------------------------------------------------------------

it creates a index.html with all the files in a given dir .

Is it possible? how?

btw: can some one show me some links about HOWTO PHP or something like that ... PHP tutorials... etc.

Thanks
Spooky
 
Old 12-15-2003, 10:26 AM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
You wouldn't be able to do this with HTML alone. You will need some sort of server-side scripting language, such as PHP, or a CGI app. Take a look at http://www.php.net for some good PHP references.
 
Old 12-15-2003, 11:47 AM   #3
Ashkhan
Member
 
Registered: Oct 2003
Distribution: Debian, Solaris, MacOS
Posts: 39

Rep: Reputation: 16
The best way to learn PHP is reading a book. You will find there all basics and some advanced topics and many examples, which will certainly help you.

Last edited by Ashkhan; 12-15-2003 at 11:48 AM.
 
Old 12-15-2003, 11:53 AM   #4
Spooky
Member
 
Registered: Dec 2002
Location: Portugal
Distribution: Fedora Core 5
Posts: 82

Original Poster
Rep: Reputation: 15
And about my "index" problem how can i do it in php?
 
Old 12-15-2003, 12:33 PM   #5
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Here's a PHP script I use to show a list of all JPG files in a directory. It assumes that directories have no "." in them, and that anything w/o a "." in it is a directory, (I was too lazy to lookup how to check for the file attributes in PHP at the time I wrote this. ) but it should serve as an example:

Code:
<?
$dir = opendir("./");
$filelist = array();
$dirlist = array();

while ($file = readdir($dir))
{
        if (strchr($file, ".jpg") !== false ||
                strchr($file, ".JPG") !== false)
        {
                array_push($filelist, $file);
        }
        else if (strchr($file, ".") === false)
        {
                array_push($dirlist, $file);
        }
}

sort($filelist);
reset($filelist);

sort($dirlist);


?>

<table border=0; cellspacing=0;cellpadding=0>
<?
while(list($index, $dir) = each($dirlist))
{
        $link = "$dir/";
        ?>
        <tr><td><a href="<?=$link?>"><?=$dir?></a></td></tr>
        <?
}

while(list($index, $file) = each($filelist))
{
        $link = "$file";
        ?>
        <tr><td><a href="<?=$link?>"><?=$file?></a></td></tr>
        <?
}
?>
</table>

Last edited by deiussum; 12-15-2003 at 12:41 PM.
 
Old 12-15-2003, 05:07 PM   #6
Spooky
Member
 
Registered: Dec 2002
Location: Portugal
Distribution: Fedora Core 5
Posts: 82

Original Poster
Rep: Reputation: 15
Nice... but for example... how does that example work?... where do i place it to work?... and can i make it work in a dinamic button or something like that... can't i make for example this command work " ln -s ... " and then make it show the dir?

I have to learn more of PHP and how it works to start doing stuff like that on my own... but i guess it's a start...

thanks for the help
Spooky

Last edited by Spooky; 12-15-2003 at 05:14 PM.
 
Old 12-16-2003, 08:11 AM   #7
Ashkhan
Member
 
Registered: Oct 2003
Distribution: Debian, Solaris, MacOS
Posts: 39

Rep: Reputation: 16
When you want to run it from web you need Apache and PHP to be installed.
Then you place your myscript.php file into "DocumentRoot" directory. Then you can call it: http://localhost/myscript.php in your browser.
 
Old 12-16-2003, 03:47 PM   #8
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Yes, you need to have a PHP module installed. My example code is saved into a file called index.php. And when you view it, it gives you a list of the files. It was something I put together quickly because I wanted to show some people a bunch of digital photos I had taken, but I didn't want to allow directory browsing under Apache. I keep meaning to expand it somewhat and make it check/display various file attributes, but I've been too lazy to do that.
 
Old 01-01-2004, 12:18 PM   #9
Spooky
Member
 
Registered: Dec 2002
Location: Portugal
Distribution: Fedora Core 5
Posts: 82

Original Poster
Rep: Reputation: 15
i change it to show ALL the files in this dir...

$dir = opendir("../temp");
$filelist = array();
$dirlist = array();

while ($file = readdir($dir))
{
if (strchr($file, ".") !== false)
{
array_push($filelist, $file);
}
else array_push($dirlist, $file);
}

ok... this is about showing what we have in a given dir but for instance can we execute the command like ... " ln -s ../dir/* ./ " to create the symbolic links and let's say chmod commands? or we realy have to enter the shell and execute them?


Last edited by Spooky; 01-01-2004 at 12:56 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic shell commands pppaaarrrkkk Linux - Newbie 7 02-05-2007 08:31 AM
Commands/Shell script ?? paraiso Linux - Newbie 11 04-21-2005 11:58 AM
Fedora Shell Commands tregg Fedora 3 01-12-2005 05:52 AM
unixs shell commands djgerbavore Programming 3 10-12-2004 01:12 PM
shell commands! krishlinux General 1 10-05-2003 05:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration