Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Marcos Thiago M. Fabis  >  Simple Secure Upload  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Usage sample
Class: Simple Secure Upload
Manage file uploads via forms with security checks
Author: By
Last change: little changes.
Date: 2004-08-23 04:37
Size: 3,884 bytes
 

Contents

Class file image Download
<?php
/**
 * Example file
 * 
 * @author   Marcos Thiago <fabismt@yahoo.com.br>
 * @version  1.0
 * @since    06/2004
 * @package  UPLOAD_FILES
 */

require_once("class_UPLOAD.php");
$upload =& new UPLOAD_FILES();

if(
$_FILES){
  foreach(
$_FILES as $key => $file){

    
$upload->set("name",$file["name"]); // Uploaded file name.

    
$upload->set("type",$file["type"]); // Uploaded file type.
    
    
$upload->set("tmp_name",$file["tmp_name"]); // Uploaded tmp file name.
    
    
$upload->set("error",$file["error"]); // Uploaded file error.
    
    
$upload->set("size",$file["size"]); // Uploaded file size.
    
    
$upload->set("fld_name",$key); // Uploaded file field name.
    
    
$upload->set("max_file_size",40960); // Max size allowed for uploaded file in bytes = 40 KB.
    
    
$upload->set("supported_extensions",array("gif" => "image/gif" ,"jpg" => "image/pjpeg","jpeg" => "image/pjpeg" ,"png" => "image/x-png")); // Allowed extensions and types for uploaded file.
    
    
$upload->set("randon_name",FALSE); // Generate a unique name for uploaded file? bool(true/false).

    
$upload->set("replace",FALSE); // Replace existent files or not? bool(true/false).
    
    
$upload->set("file_perm",0444); // Permission for uploaded file. 0444 (Read only).

    
$upload->set("dst_dir",$_SERVER["DOCUMENT_ROOT"]."/upload_dir/"); // Destination directory for uploaded files.

    
$result $upload->moveFileToDestination(); // $result = bool (true/false). Succeed or not.
  
}
}
?>
<html>
<head>
<title>SIMPLE SECURE UPLOAD</title>
<style>
.TABLE,TD,INPUT{
  font-size:11px;
  font-family:Verdana,Arial;  
}
</style>
</head>
<body>
<form name="upload" id="upload" method="POST" enctype="multipart/form-data" action="<?=$_SERVER["PHP_SELF"]?>">
<table cellpadding=2 cellspacing=2 border=0 align=center>
  <tr><td>&nbsp;</td></tr>
  <tr>
    <td align=center><b>Simple Secure Upload usage sample script by Marcos Thiago M. Fabis &lt<a href="mailto:Marcos Thiago <fabismt@yahoo.com.br>">fabismt@yahoo.com.br</a>&gt</b></td>
  </tr>
  <tr><td>&nbsp;</td></tr>
  <tr>
    <td>
      <table cellpadding=2 cellspacing=2 border=0 align=center>
        <tr>
          <td><b>File:</b></td>
          <td>
            <input type="file" name="file" id="file" size="20">
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr><td>&nbsp;</td></tr>
  <tr>
    <td>
      <table cellpadding=2 cellspacing=2 border=0 align=center>
        <tr>
          <td><b>File 1:</b></td>
          <td>
            <input type="file" name="file_1" id="file_1" size="20">
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr><td>&nbsp;</td></tr>
  <tr>
    <td>
      <table cellpadding=2 cellspacing=2 border=0 align=center>
        <tr>
          <td><b>File 2:</b></td>
          <td>
            <input type="file" name="file_2" id="file_2" size="20">
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr><td>&nbsp;</td></tr>
  <tr>
    <td>
      <table cellpadding=2 cellspacing=2 border=0 align=center>
        <tr>
          <td><b>File 3:</b></td>
          <td>
            <input type="file" name="file_3" id="file_3" size="20">
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td align=center><input type="submit" name="submit" id="submit" value="Upload"></td>
  </tr>
  <tr><td>&nbsp;</td></tr>
  <tr>
    <td>
    <?
    
if($upload->succeed_files_track || $upload->fail_files_track){
      print 
"<pre>";
      print 
"<b>Succeed Files Track Array:<br></b>";
      
print_r($upload->succeed_files_track); 
      print 
"<b>Fail Files Track Array:<br></b>";
      
print_r($upload->fail_files_track); 
      print 
"</pre>";
    }
    
?>
    </td>
  </tr>
</table>
</form>
</body>
</html>