Like this code?
Show the author your appreciation.
updir will alow you to create directories, upload files and to list and download the files.
<?php
/*
UPDIR by Christian Haensel
http://www.chftp.com
haensel@chftp.com
This scriupt will give a very basic file listing with an insecure upload functionality.
Do not use this on a public website, as it is vulnerable to many hack attempts.
Use this script only in secure areas !!! I do not take any responsibility for any damage caused
by the use of this script.
You may alter and freely redistribute this script as long as you let me know by email.
You may NOT remove the footer information without WRITTEN PERMISSION from the author.
If you made alterations to the script, let me know and I will publish you script along with mine,
if you like.
In any case: let me know what you think.
16.01.2008 Christian Haensel
*/
function readsubdirs ( $pathname ) {
$root = opendir ( "." );
echo '<select name="' . $pathname . '">' . "\n" ;
$selected = $_POST [ 'seldir' ];
while( $subs = readdir ( $root )) {
if( filetype ( $subs ) == "dir" ) {
if( $subs != "." && $subs != ".." ) {
if( $subs == $selected ) {
$sel = " selected" ;
} else {
$sel = "" ;
}
echo '<option ' . $sel . ' value="' . $subs . '">' . $subs . '</option>' . "\n" ;
}
}
}
echo '</select>' ;
}
function getfilelist ( $root ) {
$dir = opendir ( $root );
$i = 0 ;
while( $file = readdir ( $dir )) {
if( $file != "." && $file != ".." && filetype ( $file ) != "dir" ) {
if( $i % 2 ) {
echo '<div class="filelist_blue"><a href="' . $root . '/' . $file . '">' . $file . '</a></div>' . "\n" ;
} else {
echo '<div class="filelist_gray"><a href="' . $root . '/' . $file . '">' . $file . '</a></div>' . "\n" ;
}
$i ++;
}
}
}
function movefile () {
$targetpath = $_POST [ 'uploadto' ];
$target = $targetpath . '/' . basename ( $_FILES [ 'uploadedfile' ][ 'name' ]);
echo $target . "<br>" ;
if( move_uploaded_file ( $_FILES [ 'uploadedfile' ][ 'tmp_name' ], $target )) {
echo "The file " . basename ( $_FILES [ 'uploadedfile' ][ 'name' ]). " has been uploaded" ;
} else{
echo "There was an error uploading the file, please try again!" ;
}
}
function makedir () {
$createdir = $_POST [ 'makedir' ];
if( mkdir ( $createdir )) {
echo 'Directory <i>' . $createdir . '</i> created' ;
} else {
echo 'Directory could not be created' ;
}
}
?>
<html>
<head>
<style type="text/css">
body {
margin:0;
color:#000000;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
}
div.top {
top:0;
left:0;
position:relative;
width:100%;
}
div.selectdir {
display:block;
background-color:#CCCCCC;
padding:5px;
}
div.upload {
display:block;
background-color:#66CCFF;
padding:5px;
}
div.mkdir {
display:block;
background-color:#d1e0c7;
padding:5px;
}
div.content {
width:100%;
top:10px;
position:relative;
}
div.filelist_blue {
display:block;
background-color:#dceefd;
padding:2px;
padding-left:15px;
}
div.filelist_gray {
display:block;
background-color:#edeeef;
padding:2px;
padding-left:15px;
}
div.bottom {
display:block;
color:#999999;
font-size:10px;
padding-top:15px;
text-align:center;
}
</style>
</head>
<body>
</div>
<div class="top">
<div class="upload">
<form enctype="multipart/form-data" name="upload" action="#" method="post">
<input name="uploadedfile" type="file" disabled="disabled" />
<?
readsubdirs ( "uploadto" );
?>
<input type="submit" value="Upload file to selected directory" />
</form>
<?
if(isset( $_POST [ 'uploadto' ])) {
movefile ();
}
?>
</div>
<div class="selectdir">
<form name="seldir" action="#" method="post">
<?
readsubdirs ( "seldir" );
?>
<input type="submit" value="Select Directory" />
</form>
</div>
<div class="mkdir">
<form name="mkdir" action="#" method="post">
<input type="text" name="makedir" size="15" />
<input type="submit" value="Create Directory" />
</form>
<?
if(isset( $_POST [ 'makedir' ])) {
makedir ();
}
?>
</div>
</div>
<div class="content">
<?
if(isset( $_POST [ 'seldir' ])) {
$root = $_POST [ 'seldir' ];
} else {
$root = "." ;
}
getfilelist ( $root );
?>
<div class="bottom">
Script "updir" by Christian Haensel | http://www.chftp.com | haensel@chftp.com
</div>
</div>
</body>
</html>
Directory TreeView - File Manager & Explorer - FTP - Utility - PHP/HTML - Categories : PHP , Directories , FTP , Filesystem , HTML and PHP 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 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 getDirArray(Path,Filter,Sorted): Returns an array of the files in a directory,
filtered by regular expression and either sorted or randomized. Good for
random pictures and graphics. Categories : PHP , 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 Extended Get File List Function Categories : PHP , Filesystem , Search , Directories 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 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 A function which places the path and name of all subdirectories into an array Categories : PHP , Filesystem , Arrays , Directories PHP4 DirectoryIterator Class Categories : PHP , PHP Classes , Filesystem , Directories Using PHP to Delete a directory with all sub directories and files using FTP Categories : PHP , FTP , Directories , Filesystem 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 Open directory and File download Categories : PHP , Filesystem , Directories , HTML and PHP List the content of the directory of your webserver where this small PHP Script resides. Categories : PHP , Filesystem , Directories , CSS Convert a File database into MySQL Categories : PHP , Filesystem , Databases , MySQL , Beginner Guides