File Manipulation Code

  Home arrow File Manipulation Code arrow Uploader ver 2
FILE MANIPULATION CODE

Uploader ver 2
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2002-01-18

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    This enhancement of Uploder, I add a space quota restriction and file extension filtering.

    By : wibi

    <?
    /********************************************************************
    * file uploader - file uploader code snippet.
    * maxsize :
    * - you can set the maxsixe, if file size exceed maxsize it won't proceed;
    * - you can set the quota, if dir size exceed quota it won't proceed;
    * - you can set the ext, if file name extension listed on this array it won't proceed;
    *
    * Copyright (C) 2001 Wibisono Sastrodiwiryo.
    * This program is free software licensed under the
    * GNU General Public License (GPL).
    *
    * CyberGL => Application Service Provider
    * http://www.cybergl.co.id
    * office@cybergl.co.id
    *
    * $Id: uploader2.php3,v 0.2 2001/07/23 22:3:34 wibi Exp $
    *********************************************************************/
    $dir ="/www/servers/upload"; # your uploaded file dir, this dir require proper permission to write access
    $temp ="/tmp"; # unix system temp dir
    $maxsize ="40960"; # max 40 Kb
    $quota = 524288; # define space quota 500 Kb
    $ext = array(".p", ".php", ".php3", ".phtml", ".shtml"); # define file extension to reject

    if ($userfile AND $userfile != "none") {
    $total=0;
    $handle=opendir($dir);
    while ($file = readdir($handle)) {
    if (is_file("$dir/$file")) {$total+=filesize("$dir/$file");}
    }
    while (list($key,$val) = each($ext)) {
    if (strstr($userfile_name, $val)) {$invalidext=true;break;}
    }
    if ($userfile_size > $maxsize) {echo "ERR: File too large";}
    elseif ($invalidext) {echo "ERR: Forbiden file extension";}
    elseif ($total > $quota) {echo "ERR: Space quota exceeded";}
    else {
    rename("$userfile", "$temp/$userfile_name");
    copy("$temp/$userfile_name", "$dir/$userfile_name");
    unlink("$temp/$userfile_name");
    echo "OK: File \"$userfile_name\" uploaded succesfully";
    }
    } else {
    ?>
    <form action="<?echo $PHP_SELF?>" method=POST ENCTYPE="multipart/form-data">
    <table>
    <tr>
    <td class=navbox>Select File:</td>
    <td>:</td>
    <td><input type=file name=userfile></td>
    </tr>
    <tr>
    <td class=navbox>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type=submit value=Upload></td>
    </tr>
    </table>
    </form>
    <?}?>
    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

    blog comments powered by Disqus

    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-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap