|
|
|
|
|
|
| |
| <?php
$folder = $DOCUMENT_ROOT."/files/"; // the folder which you want to open
function select_files($dir) {
global $PHP_SELF;
$teller = 0;
if ($handle = opendir($dir)) {
$mydir = "<p>These are the files in the directory:</p>\n";
$mydir .= "<form name=\"form1\" method=\"post\" action=\"".$PHP_SELF."\">\n";
$mydir .= " <select name=\"file_in_folder\">\n";
$mydir .= " <option value=\"\" selected>... \n";
while (false !== ($file = readdir($handle))) {
$files[] = $file;
}
sort($files);
foreach ($files as $val) {
if ($val != "." && $val != "..") {
$mydir .= " <option value=\"".$val."\">";
$mydir .= (strlen($val) > 30) ? substr($val, 0, 30)."...\n" : $val."\n";
$teller++;
}
}
$mydir .= " </select>";
$mydir .= "<input type=\"submit\" name=\"download\" value=\"Download\">";
$mydir .= "</form>\n";
closedir($handle);
}
if ($teller == 0) {
echo "No files!";
} else {
echo $mydir;
}
}
if (isset($download)) {
$fullPath = $folder.$_POST['file_in_folder'];
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "png":
header("Content-type: image/png");
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
break;
case "zip":
header("Content-type: application/zip");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Content-length: $fsize");
header("Cache-control: private");
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Demo: File upload/download and open directory</title>
<style type="text/css">
<!--
body {
font-family: Arial, Helvetica, sans-serif;
text-align:center;
}
p {
font-size: 14px;
line-height: 20px;
}
#main {
width:350px;
margin:0 auto;
padding:10px;
text-align:left;
border: 1px solid #000000;
}
-->
</style>
</head>
<body onLoad="javascript:window.resizeTo(425,555);return false;">
<div id="main">
<h2 style="text-align:center;margin-top:10px;">Open directory and <br>
File download </h2>
<?php echo select_files($folder); ?>
<p style="margin-top:40px;">Find more information about the directory and download function on: <a href="http://www.finalwebsites.com/snippets.php" target="_blank">www.finalwebsites.com</a></p>
</div>
</body>
</html> | | |
|
| Directory viewer, customize how you display the file structure, easy to
understand. Found out about PHP 3 days ago, and this is my first prog. Categories : HTML and PHP, Complete Programs, Directories, Filesystem, PHP | | | Directory TreeView - File Manager & Explorer - FTP - Utility - PHP/HTML - Categories : PHP, Directories, FTP, Filesystem, HTML and PHP | | | Random Image Display Categories : PHP, Filesystem, Graphics, HTML and PHP | | | Display list of files within current and subdirectories (recursively) showing
each file as an anchored link and each directory as a category header. Categories : Filesystem, Directories, Arrays, PHP | | | Extended Get File List Function Categories : PHP, Filesystem, Search, Directories | | | a file explorer for the web, filesystem php php3 files dirs directories pictures files windows linux system list ls scripts Categories : PHP, URLs, Directories, Filesystem | | | How to let a user download a picture by clicking on it instead of needing to right click and Save-As. Categories : HTTP, PHP, HTML and PHP, Filesystem | | | upload function using PHP's FTP abilities. Categories : PHP, Filesystem, HTML and PHP | | | A function which places the path and name of all subdirectories into an array Categories : PHP, Filesystem, Arrays, Directories | | | Directory Viewer, Directory Content Viewer, Directory Structure to HTML.
This code will basically create a complete set of HTMLs to let a user
navigate through any directory you want. Excellent code for large file
sharing pages. Categories : Directories, Filesystem, PHP | | | List the content of the directory of your webserver where this small PHP Script resides. Categories : PHP, Filesystem, Directories, CSS | | | grab directory listings into an array the example prints out each
subdirectory in the main dir - further work is to be performed on this one Categories : Filesystem, PHP, Directories, Search, Utilities | | | Opening and formatting text files into HTML on the fly- or HTML from templates. Categories : PHP, HTML and PHP, Filesystem | | | PHP4 DirectoryIterator Class Categories : PHP, PHP Classes, Filesystem, Directories | | | Listing the 10 most recently updated files in a given dir by using last-
modified variable and printing to html with link to the file Categories : PHP, Directories, Filesystem | |
|
|
|