File Manipulation Code
  Home arrow File Manipulation Code arrow File management
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
FILE MANIPULATION CODE

File management
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-10-05

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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'>
    &nbsp;&nbsp;&nbsp;File: <INPUT TYPE='FILE' NAME='uploadfile' maxlength='255'>&nbsp;&nbsp;&nbsp;
    <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'>
    &nbsp;&nbsp;&nbsp;Create directory: <INPUT TYPE='text' NAME='create_dir'>&nbsp;&nbsp;&nbsp;
    <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.="|&nbsp;&nbsp;<a class='text' href=?action=3&change_path=$path/$file>$file</a>&nbsp;&nbsp;|";
    }
    if (is_file($file))
    {
    $file_del=ereg_replace(" ","_",$file);
    $list.="&nbsp;&nbsp;<a class='text' href=?action=4&file=$file_del&path=$path&subdir=$subdir>[delete]</a>&nbsp;&nbsp;&nbsp;<a class='text' href='" . ereg_replace("$DOCUMENT_ROOT","",$path) ."/$file' target='_blank'>$file</a>&nbsp;&nbsp;<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>|&nbsp;&nbsp;Back&nbsp;&nbsp;|</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>
    &nbsp;&nbsp;<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

     

    IBM® developerWorks developerWorks - FREE Tools!


    IBM DB2 Deep Compression ROI Tool

    The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times.
    FREE! Go There Now!


    NEW! Accelerating Software Innovation on i on Power Systems

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, for an overview of Rational’s new software offerings and resources to help modernize and accelerate software innovation on i on Power Systems – while ensuring past application investments are protected and continue to grow. Learn how these solutions are helping customers extend their core i5/OS solutions toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    FREE! Go There Now!


    Role of Integrated Requirements Management in Software Delivery

    As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change.
    FREE! Go There Now!


    NEW! Hello World: Learn how to install and use the Rational Asset Manager Eclipse client

    In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset.
    FREE! Go There Now!


    NEW! Evaluate Rational Business Developer V7.1

    Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities.
    FREE! Go There Now!


    NEW! Webcast: IBM Rational Build Forge - Beyond the Build

    The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size.
    FREE! Go There Now!


    NEW! Rational Modeling Extension for Microsoft.Net

    Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms.
    FREE! Go There Now!


    NEW! The role of integrated requirements management in software delivery

    This paper is about the critical role that a discipline called integrated require­ments management can play in helping to ensure that your business goals and IT investments are continuously aligned—whether you are sourcing, integrat­ing, building or maintaining software. It also looks at ways that automated IBM Rational® products can work together to help you use requirements in the very best way.
    FREE! Go There Now!


    NEW! Project and Portfolio Management Executive Resource Kit

    Portfolio Management is about effectively managing portfolio value by aligning portfolio investments with business goals. This complimentary e-kit provides a collection of materials that can help you understand how IBM Rational enables and automates best practices for improved governance and clear visibility into portfolio and project performance across the entire IT project lifecycle.
    FREE! Go There Now!


    NEW! IBM – Taking Web 2.0 to Work

    David Barnes, Lead Evangelist for IBM Emerging Internet Technologies will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    FILE MANIPULATION CODE ARTICLES

    - Bandwidth Control with pure PHP
    - Eazy Gallery
    - file_get_contents for PHP < 4.3.0
    - PHP Class: Image Snapshot 1.3
    - Universal downloader
    - Image Gallery v2.0
    - Free/Used Disk Space
    - Directory Lister
    - Directory image view, with selective hidden
    - Move or Copy a Directory (and files and sub ...
    - Ensure_Sub_Directory_Exists
    - Wedit
    - Form Examples Text Boxes to Drop Downs
    - myFiles
    - List files in a directory, no subdirectories





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek