This script will allow you to manage directories and files.
The only thing you need to do is create a directory where you put the files. You have to add the name of that directory in the file, so just change $file_dir="files"; into the directory you made.
Just unzip the file I posted here. These files don't have to be in the $DOCUMENT_ROOT/$file_dir
notice that if the file_dir is $DOCUMENT_ROOT/downloads/files you wil have to edit the $file_dir into "/downloads/files"
You can create directories in the file_dir and in the subdirectories when you are browsing them, you can also delete the directories, but as you can see when you do so the content of the directory wil be lost too.
You can upload, see and delete files in the same screen.
I haven't made a check on the delete button so if you push it it wil be deleted right away.
By : Orcrist
<HTML>
<HEAD>
<TITLE>File/Backup management screen</TITLE>
<link href='default.css' rel='stylesheet' type='text/css'>
</HEAD>
<BODY>
<?php
$file_dir="files";
function place($path)
{
echo "
<span class='title'>File/backup upload</span><img src=\"spacer.gif\" width='100%' height='10'><br>
<span class='text'>This is an area where you can upload and manage your files for school.<br>To upload the file click browse for the image in your computer and press upload.</span><img src=\"spacer.gif\" width='100%' height='7'><br>
<table border='0' bgcolor='#000000' cellpadding='1' cellspacing='1'>
<tr>
<td align='center'>
<table border='0' cellpadding='0' cellspacing='0' bgcolor='#FFFFFF'>
<tr>
<td align='center' valign='top'><img src=\"spacer.gif\" width='100%' height='15'></td>
</tr>
<tr>
<td align='center'>
<FORM ENCTYPE='multipart/form-data' ACTION='' METHOD='POST'>
File: <INPUT TYPE='FILE' NAME='uploadfile' maxlength='255'>
<INPUT TYPE='hidden' name='action' VALUE='5'>
<INPUT TYPE='hidden' name='path' VALUE='$path'>
</td>
</tr>
<tr>
<td align='center'>
<INPUT TYPE='submit' VALUE='Upload'>
</td></FORM>
</tr>
<tr>
<td align='center' valign='top'><img src=\"spacer.gif\" width='100%' height='15'></td>
</tr>
</table>
</td>
</tr>
</table>
";
}
function place_bottom($path)
{
echo "
<span class='title'>Directory Create</span><img src=\"spacer.gif\" width='100%' height='10'><br>
<span class='text'>This is an area where you can create a directory.<br>To create one you type the name in the field and push create.</span>
<img src=\"spacer.gif\" width='100%' height='7'><br>
<table border='0' bgcolor='#000000' cellpadding='1' cellspacing='1'>
<tr>
<td align='center'>
<table border='0' cellpadding='0' cellspacing='0' bgcolor='#FFFFFF'>
<tr>
<td align='center' valign='top'><img src=\"spacer.gif\" width='100%' height='15'></td>
</tr>
<tr>
<td align='center'>
<FORM ACTION='' METHOD='POST'>
Create directory: <INPUT TYPE='text' NAME='create_dir'>
<INPUT TYPE='hidden' name='action' VALUE='1'>
<INPUT TYPE='hidden' name='path' VALUE='$path'>
</td>
</tr>
<tr>
<td align='center'>
<INPUT TYPE='submit' VALUE='Create'>
</td></FORM>
</tr>
<tr>
<td align='center' valign='top'><img src=\"spacer.gif\" width='100%' height='15'></td>
</tr>
</table>
</td>
</tr>
</table>
";
} // einde place_bottom()
function pics_onsite($path,$DOCUMENT_ROOT,$subdir)
{
global $file_dir;
if (!chdir($path))
{
echo "Error: directory: $path not found....";
}
$handle=opendir('.');
$count=0;
$list= "<table border='0' cellspacing='1' cellpadding='1' bgcolor='#000000'>
<tr><td valign='top' bgcolor='#FFFFFF'><img src=\"spacer.gif\" width='100%' height='7'><br>";
$directory= "<table border='0' cellspacing='1' cellpadding='1' bgcolor='#000000'>
<tr><td valign='top' bgcolor='#FFFFFF' align='center'><img src=\"spacer.gif\" width='100%' height='7'><br>";
if (ereg_replace("$DOCUMENT_ROOT/$file_dir","",$path)!="")
{
$subdir=1;
}
else
{
$subdir=0;
}
while (($file = readdir($handle))!==false)
{
if (($file != ".") && ($file != ".."))
{
if (is_dir($file))
{
$directory.="| <a class='text' href=?action=3&change_path=$path/$file>$file</a> |";
}
if (is_file($file))
{
$file_del=ereg_replace(" ","_",$file);
$list.=" <a class='text' href=?action=4&file=$file_del&path=$path&subdir=$subdir>[delete]</a> <a class='text' href='" . ereg_replace("$DOCUMENT_ROOT","",$path) ."/$file' target='_blank'>$file</a> <br>";
$count++;
if ($count==10){$list.="<img src=\"spacer.gif\" width='100%' height='7'></td><td valign='top' bgcolor='#FFFFFF'><img src=\"spacer.gif\" width='100%' height='7'><br>"; $count=0;}
$wel=1;
}
}
}
if (!$wel){$list.="<center><img src=\"spacer.gif\" width='10' height='7'><span class='textbold'>No files in this directory try another</span><img src=\"spacer.gif\" width='10' height='7'></center>";}
$list.="<img src=\"spacer.gif\" width='100%' height='7'></td></tr></table>";
if ($subdir){$directory.="<a class='text' href=?action=2>| Back |</a>";}
$directory.="<img src=\"spacer.gif\" width='100%' height='7'></td></tr></table>";
echo "
<center>
<span class='textbold'>Carefull with the delete function, it wil delete it all (no control).</span>
<table border=0>
<tr>";
if (ereg_replace("$DOCUMENT_ROOT/$file_dir","",$path)!="")
{
echo "<td align='center' valign='top' class='text'>
You are in directory: <span class='title'>" . ereg_replace("$DOCUMENT_ROOT/$file_dir","",$path) ."</span>
<a class='text' href=?action=6&del_path=$path>[delete_DIR]</a></td>";
}
else
{
echo "<td align='center' valign='top'><img src=\"spacer.gif\" width='100%' height='10'></td>";
}
echo "
</tr>
<tr>
<td align='center' class='text'>Below you will view list of existing files.</td>
</tr>
<tr>
<td align='center' valign='top'><img src=\"spacer.gif\" width='100%' height='7'></td>
</tr><tr>
<td align='center' valign='top'>$directory</td>
</tr>
<tr>
<td align='center' valign='top'><img src=\"spacer.gif\" width='100%' height='7'></td>
</tr>
<tr>
<td align='center' valign='top'>$list</td>
</tr>
</table>
</center>
";
} // einde pics_onsite()
function delete($file)
{
global $message,$path;
if (file_exists($file))
{
chmod($file,0777);
if (is_dir($file))
{
$handle = opendir($file);
while ($filename = readdir($handle))
{
if ($filename != "." && $filename != "..")
{
delete ($file."/".$filename);
}
}
closedir($handle);
if (rmdir($file)){$message.="Directory: " . ereg_replace("$path","",$file) .", deleted<br>";}
}
else
{
if (unlink($file)){$message.="File: " . ereg_replace("$path","",$file) .", deleted<br>";}
}
}
} // einde delete($file)
if (!$path)
{
$path="$DOCUMENT_ROOT/$file_dir";
}
switch ($action)
{
case 1:
$path="$path/$create_dir";
mkdir("$path", 0777);
break;
case 2:
$subdir=0;
break;
case 3:
$path="$change_path";
$subdir=1;
break;
case 4:
$message="<br><br><center><table border='0' cellspacing='1' cellpadding='1' bgcolor='#000000'>
<tr><td valign='top' bgcolor='#FFFFFF' class='text'><img src=\"spacer.gif\" width='100%' height='7'><br>";
IF (@is_file("$path/$file"))
{
@unlink ("$path/$file");
}
ELSE
{
$file=ereg_replace("_"," ",$file);
IF (is_file("$path/$file"))
{
unlink ("$path/$file") or die ("error: $path/$file");
}
}
break;
case 5:
$doel="$path/$uploadfile_name";
IF (!copy ($uploadfile,$doel))
{
echo "Error copying: ($uploadfile) to: ($doel)";
}
break;
case 6:
$message="<br><br><center><table border='0' cellspacing='1' cellpadding='1' bgcolor='#000000'>
<tr><td valign='top' bgcolor='#FFFFFF' class='text'><img src=\"spacer.gif\" width='100%' height='7'><br>";
delete($del_path);
$message.="<img src=\"spacer.gif\" width='100%' height='7'></td></tr></table></center>";
break;
}
echo "
<center>
<table border='0' bgcolor='#000000' cellpadding='1' cellspacing='1'>
<tr>
<td align='center'>"; place($path); echo "<br></td><td align='center'>"; place_bottom($path); echo "<br></td>
</tr>
<tr>
<td align='center' colspan='2'>"; pics_onsite($path,$DOCUMENT_ROOT,$subdir); echo "</td>
</tr>
</table>
$message
</center>
";
?>
</BODY>
</HTML>
Click to
Download File| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More File Manipulation Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br /> FREE! Go There Now!
|
|
|
|
You probably have thousands of lines of COBOL code loaded with business intelligence and being used to run your business, along with an army of developers maintaining these applications. Learn how to prepare your applications and developers so you can keep that competitive edge and move to a service-oriented architecture with the IBM Rational Enterprise Modernization solutions. Replay is available for 9 months. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download the latest trial version of IBM Data Studio V1.1 at no cost. IBM Data Studio is a comprehensive data management solution that helps you effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life cycle utilizing a consistent and integrated user interface. Unlike other client-side data management solutions that focus on only one aspect of the application lifecycle or database administration, Data Studio complements the Rational Software Delivery platform, providing unparalleled flexibility for a heterogeneous data server environment across platforms. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial of the Rational Host Access Transformation Services (HATS) Toolkit. The HATS toolkit provides a set of plug-ins for the IBM Rational Software Delivery Platform to help you easily extend your legacy applications. HATS makes your 3270 and 5250 applications available as HTML through the most popular Web browsers, while converting your host screens to a Web look and feel and it also enables you to develop new Web, portal, and rich-client applications. FREE! Go There Now!
|
|
|
|
Join this webcast to see how IBM Data Studio Developer and pureQuery can take the pain out of Java data access. uApplications developed using both Java and SQL have become a common requirement. Database connectivity using Java Database Connectivity (JDBC) to create an application is a multi-step tedious process, and tooling that covers both SQL and Java has been unavailable, until now. IBM Data Studio introduces the pureQuery platform: a high-performance, Java data access platform focused on simplifying the tasks of developing, managing, and optimizing database applications and services. FREE! Go There Now!
|
|
|
|
Listen to this webcast to get an overview of Info 2.0 and a technical demo of how to quickly build an enterprise mashup. IBM's Info 2.0 technology leverages emerging Web 2.0 technologies such as mashups, feeds, AJAX, and JSON in order to simplify assembly of information using feeds and services. Come learn about the technical elements of Info 2.0 including the Feed Generation framework, Mashup Engine, and mashup assembly components. Learn how to pull information from databases, departmental information, and the Web to create mashups critical to your company’s success. We will also discuss best practices to help you get started. FREE! Go There Now!
|
|
|
|
This Fall, IBM Rational talks to you directly through a special teleconference series giving you access to the best minds in IBM Rational - product experts and market thought leaders who will answer your questions during these pre-scheduled telephone conference calls. Register today! FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Performance Tester V7.0.1, a load and performance testing solution for teams concerned about the scalability of their Web-based applications. Combining multiple ease-of-use features with granular detail, Rational Performance Tester simplifies the test-creation, load-generation and data-collection processes that help teams ensure the ability of their applications to accommodate required user loads. FREE! Go There Now!
|
|
|
|
You can now evaluate IBM Rational Asset Manager V7.0 online without installing or configuring it on your own system! Rational Asset Manager helps create, modify, govern, find, and reuse any type of development assets, including SOA and systems development assets. Rational Asset Manager helps you reduce software development costs and improve quality by facilitating the reuse of all types of software development-related assets. Visit developerWorks to learn more about this product and register to explore its capabilities online. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |