Auto index help

Started on the old forum in November 2011 · view the original in the archive · old links redirect here

2 replies · 508 views · started 15 years ago · 1 min read

2 participants
rajveer Developer · 104 posts #1

Hai Friends i want to make downloads website using autindex php code i found this script which can be placed inside folders to autmatic show files over page

**```php

<? $items_per_page = "10"; $size_bytes = 100072000; $kb = $size_bytes / 1024; $mb = $size_bytes / 1024000; if (!isset($_GET['page'])) { $page=0; } else { $page = $_GET['page']; } $total = 0; if(!($dp = opendir("./"))) die ("Cannot open ./"); $file_array = array(); while ($file = readdir ($dp)) { if(substr($file,0,1) != '.' and $file != "index.php") { $file_array[] = $file; } } $file_count = count ($file_array); sort ($file_array); if ($file_count > 0) { $first_record = $page * $items_per_page; $last_record = $first_record + $items_per_page; while (list($fileIndexValue, $file_name) = each ($file_array)) { if (($fileIndexValue >= $first_record) AND ($fileIndexValue < $last_record)) { echo "» <a href=\"$file_name\"></a>$file_name<br/><a href=\"$file_name\">Download(". round(filesize($file_name)/1024,1) . "kb)</a><br />"; $total = $total + filesize($file_name); } } ?><hr><center><?
		if (($file_count > 0) AND ($page != 0))
			{

			
			// previous button
			
			$prev_page = $page -1;
			
			echo "<a  href=\"".$_SERVER["PHP_SELF"]."?page=$prev_page\">[Back]</a> | ";
			               
			}

		if (($file_count > 0) AND ($last_record < $file_count))
			{
			// next button
			$next_page = $page + 1;
			echo "<a href=\"".$_SERVER["PHP_SELF"]."?page=$next_page\">[Next]</a>";
			}
			
				
			echo "<br/>Directory:<br/>$file_count ";
		if ($file_count == 1)
			{echo "file";}
		else
			{echo "files";}
			
		echo " (" . round($total/1024,1) . "kb)";
		?></div><?
			// Home index
			echo " <br/><a  href=\"http://write here your url\">[Edit Your Back Link]</a>";

/*

Please Support Us by providing back Link to Our Site, Don't delete this partner link.

*/

			echo " <br/>Our Partner:";

echo " <br/><a href="http://pocketwap.net">[Pocketwap.net]</a><hr>";

		}
		
	closedir($dp);
	
	?>

**This is nice and usefull also but i want to make one change wheneve i click on download on images download i got reirect to <http://mysite/imaeg/image.gif>
insted of redirectin i want to make it direct downloadble means someone clicks on that download link and its starts doownloading automaticly i hope someone will understand what i am trying to say**
arnage Lead · 811 posts #2

Its not redirect as this is just directory listing script, that is the link to the file.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
Guest #3

you should make a PHP script that forces a download,

<?php

header('Content-type: application/YOUR_EXTENSION');

header('Content-Disposition: attachment; filename="downloaded.YOUR_EXTENSION"');

echo file_get_contents(YOUR_FILE_PATH);

hope that helps!

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close