displaying directory in html


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers displaying directory in html
# 1  
Old 10-31-2003
displaying directory in html

How would i in a csh script get it to display all the files in the current directory in html?
# 2  
Old 10-31-2003
csh script that displays html

how do i write a csh script that constructs an HTML index page for files in the current directory or files on the command line?

Thanks
# 3  
Old 10-31-2003
Presumably, you want more than just a listing of files (which can be produced without the intervention of any scripting language)?

If so, the script is called from a cgi bin and dynamically converts the data attributes (i.e. in this case a list of files) into valid HTML which is (usually) streamed to the browser.

The important line is the first output line which begins:

Content-type: text/html\n\n

The rest is just normal HTML encoding...
# 4  
Old 10-31-2003
Your browser will probably let you view directories (if you are set-up as an ftp user on your unix box). Try using the following format in your browser's address bar... ftp://logname:password@unixhost/your/directory
# 5  
Old 10-31-2003
If you don't want toenable apache's indexer for whatever reason, you can add this script, though it's in PHP:

(more revisions, etc. here: http://www.furry.ca/cgi-bin/furryca/...ct=ST;f=9;t=50 )

PHP Code:
<?php
/* Karma's Funkii Index Script CopyLeft 2003 The Entity Known As Karma Foxx
  (karma@yiffy.tk - [url]www.yiffy.tk[/url])*/

// Opening Static HTML
print("
<html>\n<head>\n<title>Index</title>\n<style>
body
{
background-color: #FFFFFF;
font-size: 10pt;
font-family: Arial, Helvetica;
color: #000000;
}
a:link
{
color: #666666;
text-decoration: none;
}
a:visited
{
color: #666666;
text-decoration: none;
}
a:active
{
color: #666666;
text-decoration: none;
}
a:hover
{
color: #999999;
text-decoration: none;
}
img
{
border: 0px;
}
</style>\n</head>\n<body>\n<center>
<font size=\"+1\">\n<b>Index of "
.exec("pwd")." | <a href=\"../\">Parent Directory</b></a>\n</font>
<table width=\"98%\" cellpadding=\"0\" cellspacing=\"2\" marginwidth=\"0\" marginheight=\"0\">
"
);

// Define functions

function makeThumb($image// Makes a thumbnail of the file in question
{
if(! 
file_exists(".thumbs/".$image))
{
if(! 
is_dir(".thumbs"))
{
mkdir(".thumbs");
}

exec("convert -size 80x60 $image -resize 80x60 .thumbs/$image");
}
}

function 
tests($file// Perform tests on the file, then output an array
{
if(
is_file($file))
{
$image_types = array("\.png""\.jpg""\.jpeg""\.jfif""\.gif""\.bmp""\.xbmp""\.tiff");
$document_types = array("\.txt""\.doc""\.rtf""\.pdf""\.ps""\.eps""\.sgml""\.DocBook");
$web_types = array("\.htm""\.html""\.shtml""\.php""\.cgi""\.pl""\.js""\.vb""\.asp");
$output[type] = "File";
foreach(
$image_types as $ext)
{
$results ereg($ext$file);
if(
gettype($results) == integer)
{
$output[type] = "Image";
}
}
foreach(
$document_types as $ext)
{
$results ereg($ext$file);
if(
gettype($results) == integer)
{
$output[type] = "Document";
}
}
foreach(
$web_types as $ext)
{
$results ereg($ext$file);
if(
gettype($results) == integer)
{
$output[type] = "Web";
}
}
}
elseif(
is_dir($file))
{
$output[type] = "Directory";
}
$output[access] = date("D d M Y g : i A"fileatime($file));
$output[mod] = date("D d M Y g : i A"filemtime($file));
$output[changed] = date("D d M Y g : i A"filectime($file));
$output[name] = $file;
$temp_size filesize($file);
// Format the file size
if($temp_size 1024)
{
$output[size] = $temp_size;
$output[sizetype] = "B";
}
elseif(
$temp_size 1048576)
{
$output[size] = round($temp_size /= 1024);
$output[sizetype] = "KB";
}
else
{
$output[size] = round($temp_size /= 1048576);
$output[sizetype] = "MB";
}
// Check permissions
if(is_readable($file))
{
$permissions "r";
}
else
{
$permissions "-";
}
if(
is_writable($file))
{
$permissions .= "w";
}
else
{
$permissions .= "-";
}
if(
is_executable($file))
{
$permissions .= "x";
}
else
{
$permissions .= "-";
}
$output[permissions] = $permissions;

return 
$output;
}

function 
showItem($file)
{

// Set the icon directory
$icons "file:/var/www/icons";
print(
"<tr>\n<td bgcolor=\"#E6E6E6\" onMouseOver=\"this.bgColor='#F6F6F6'\" onMouseOut=\"this.bgColor='#E6E6E6'\"><table border=\"0\" width=\"100%\" cellpadding=\"2\" marginwidth=\"0\" marginheight=\"0\" cellspacing=\"0\">\n<tr>\n<td width=\"80\" height=\"60\" valign=\"middle\" align=\"center\">");
if(
$file[type] == "Image")
{
makeThumb($file[name]);
print(
"
<a href=\"
$file[name]\"><img src=\".thumbs/$file[name]\"></a>
</td>
<td height=\"60\" valign=\"top\" width=\"50%\">
<b>Image Name: </b><a href=\"
$file[name]\">$file[name]</a><br>
"
);
}
elseif(
$file[type] == "Web")
{
print(
"
<a href=\"
$file[name]\"><img src=\"$icons/web.png\"></a>
</td>
<td height=\"60\" valign=\"top\" width=\"50%\">
<b>Document Name: </b><a href=\"
$file[name]\">$file[name]</a><br>
"
);
}
else
{
print(
"
<a href=\"
$file[name]\"><img src=\"$icons/$file[type].png\"></a>
</td>
<td height=\"60\" valign=\"top\" width=\"50%\">
<b>
$file[type] Name: </b><a href=\"$file[name]\">$file[name]</a><br>
"
);
}

print(
"
<b>Size: </b>
$file[size] $file[sizetype]<br>
<b>Permissions: </b>
$file[permissions]<br>
</td>
<td height=\"60\" valign=\"top\" width=\"50%\">
<b>Uploaded: </b>
$file[changed]<br>
<b>Modified: </b>
$file[mod]<br>
<b>Accessed: </b>
$file[access]<br>
</td>
</tr>
</table>\n</td>\n</tr>
"
);
}

// Feed directory contents into an array
$dh opendir(".");
while(
gettype($entries[] = readdir($dh)) != boolean)
{
$entries[] = readdir($dh);
}
closedir($dh);
sort($entries);

foreach(
$entries as $file)
{
// Exclude this document and the parent dirs from the list
if($file == "index.php" or $file == "" or $file == "." or $file == ".." or $file == ".thumbs")
{
continue;
}
showItem(tests($file));
}

// Ending Static HTML
print("</table>\n<font size=\"-1\">
This page generated on "
.date("D d M Y g : i A")." by Karma's Funkii Index Script<br>
<a href=\"mailto:karma@yiffy.tk\">Contact</a> Karma - <a href=\"http://www.yiffy.tk\">[url]www.yiffy.tk[/url]</a>
</font>\n</center>\n</body>\n</html>"
);

?>
A demonstation of this script can be found at http://karma.luniac.com/misc .
# 6  
Old 10-31-2003
Please don't double-post, adel66. That way, any answers anyone gives you to help out will all be one place.


I merged the threads, so I deleted the link to the now non-existent thread. --- Perderabo

Last edited by Perderabo; 10-31-2003 at 12:45 PM..
# 7  
Old 10-31-2003
Sorry its just that i thought i put my first post in the wrong message board thats all.

THanks.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Directory not displaying (strange)

Hi All. I am facing a strange scenario (c13:pq1:/pq1/buffer>) ll ../dataCS/* ls: cannot access ../dataCS: No such file or directory (c13:pq1:/pq1/buffer>) cd ../dataCS (c13:pq1:/pq1/dataCS>) ll * -rw-rw-r-- 1 pq1 pq10 Mar 1 13:43 test (c13:pq1:/pq1/dataCS>) ll ../dataCS/* -rw-rw-r--... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

2. Shell Programming and Scripting

Parse multiple html files in directory

I have downloaded source code for 97 files using: wget -x -i link.txt then run a rename loop: for file in * do mv $file $file.txt done to keep the html tags but make the file a text that can be parsed. In each of the 97 txt files the gene # is variable, but the gene is associated... (15 Replies)
Discussion started by: cmccabe
15 Replies

3. Shell Programming and Scripting

Need script to remove millions of tmp files in /html/cache/ directory

Hello, I just saw that on my vps (centOS) my oscommerce with a seo script has created millions of tmp files inside the /html/cache/ directory. I would need to remove all those files (millions), I tried via shell but the vps loads goes to very high and it hangs, is there some way to do a... (7 Replies)
Discussion started by: andymc1
7 Replies

4. UNIX for Dummies Questions & Answers

Displaying the current working directory in prompt

Hi, I want that the prompt that is being displayed (i.e $ sign) should display always the current directory I am working in instead of that $ sign example: as we use PS1=patric and the prompt changes from $ to patric OR if we write the command PS1=`pwd` it will display the current... (5 Replies)
Discussion started by: premjotsingh
5 Replies

5. Shell Programming and Scripting

Displaying file in html loses format

I have a bash script to output the contents of a text file to html. Everything outputs ok, except this: ###################################################################### # # # PRIVATE/PROPRIETARY # # # # ANY UNAUTHORIZED ACCESS TO, OR MISUSE OF ABC COMPANY # # SYSTEMS OR DATA MAY... (2 Replies)
Discussion started by: numele
2 Replies

6. Web Development

html link to images in /tmp directory

Because of permission issues, I need to link to images in my web page which are stored in /tmp which of course is located in the root directory but my actual html page is much further down in another directory. I thought the the following code should work, but the image comes up as a broken link:... (2 Replies)
Discussion started by: Solerous
2 Replies

7. Shell Programming and Scripting

displaying 3 directory listings in 3 separate columns.

i having problems figuring out how to 'read' in 3 different directory listings and then display them on the screen into 3 separate columns. i thought i could use a 'for' loop to grab each directory and then assign a unique variable to each line 'read' in. of course, as you experts all know,... (16 Replies)
Discussion started by: mjays
16 Replies

8. UNIX for Dummies Questions & Answers

Displaying files in a directory

Dear Experts, I am new to UNIX and I have a script below and in this test case I am reading the names of the files in the present directory into a variable and then looping through each file name and displaying the name back to the screen. The problem I have is although there are 5 files in the... (4 Replies)
Discussion started by: markjohnlowe
4 Replies
Login or Register to Ask a Question