PHP Classes

File: uploadManager/upload.php

Recommend this page to a friend!
  Classes of Ilya Nemihin  >  Upload Manager  >  uploadManager/upload.php  >  Download  
File: uploadManager/upload.php
Role: Application script
Content type: text/plain
Description: script for user interface, showing form for add file, show list of uploaded files, also call UploadManager for perform action
Class: Upload Manager
Management of files uploaded via Web forms
Author: By
Last change:
Date: 18 years ago
Size: 2,922 bytes
 

Contents

Class file image Download
<?php

$include_root
= './include/';
include (
$include_root.'functions/ClassLoader.php' );

load_class( 'UploadManager/UploadManager.php' );
load_class( 'Http/Request.php' );

$request = new Request();

// use case 1
//$request->setParam( 'action', 'add_change_resource' );
//$request->setParam( 'descr', '' );

// use case 2
//$request->setParam( 'action', 'change_description' );
//$request->setParam( 'file_name', 'test2.txt' );
//$request->setParam( 'descr', 'new d2+' );

// use case 3
//$request->setParam( 'action', 'delete_resource' );
//$request->setParam( 'file_name', 'test2.txt' );

$FILE_STORAGE_BASE = './files';
$PAGE_NAME = 'upload.php';

$um = new UploadManager( $FILE_STORAGE_BASE );

if (
$request->getParam('action') != '' ){
 
$um->makeActionByRequest( $request );
 
Header( 'Location: '.$PAGE_NAME."\n\n" );
}

?>

<html>
<head>
<meta http-equiv="Expires" content="Thu, 01 Dec 1994 16:00:00 GMT">
<style>
body { font-family: MS Sans Serif, Tahoma, Verdana; font-size: 10pt; }
</style>
</head>
<body>

<h2>Upload manager</h2>


<h3>Uploaded file list:</h3>
<?php

foreach( $um->getFiles() as $file_item ){
  if (
$file_item['file_name'] == $request->getParam('file_change') ){
   
// edit mode
   
?>
<form action="<?php echo $PAGE_NAME?>" method="post">
      <?php echo '<a target="_blank" href="'.$FILE_STORAGE_BASE.'/'.$file_item['file_name'].'">'.$file_item['file_name'].'</a>' ?>
<input type="text" name="descr" value="<?php echo $file_item['descr']?>">
      <input type="hidden" name="file_name" value="<?php echo $file_item['file_name']?>">
      <input type="hidden" name="action" value="change_description">
      <input type="submit" value="Change">
      <input type="button" value="Cancel" onclick="location.href='<?php echo $PAGE_NAME ?>'">
      &nbsp;
      <input type="button" value="Delete" onclick="if (confirm('Delete file?')) location.href='<?php echo $PAGE_NAME ?>?action=delete_resource&file_name=<?php echo $file_item['file_name']?>'"> <?php //"?>
</form>
   <?php
 
}
  else{
   
// info mode

    // file name with href to file
   
print '<a target="_blank" href="'.$FILE_STORAGE_BASE.'/'.$file_item['file_name'].'">'.$file_item['file_name'].'</a>';
   
// description
   
print ' '.$file_item['descr'].' ';
   
// action
   
print '[ <a href="'.$PAGE_NAME.'?file_change='.$file_item['file_name'].'">change</a> ]';
    print
'<br>';
  }
}

if (
count( $um->getFiles() ) == 0 ){
  print
'none<br>';
}

?>

<h3>Add/change file</h3>

<form name="upload" enctype="multipart/form-data" action="<?php echo $PAGE_NAME?>" method="post">
  file: <input type="file" name="file_name"><br>
  descr: <input type="text" name="descr"><br>
  <input type="hidden" name="action" value="add_change_resource">
  <input type="submit" value="Add/Change file">
</form>

</body>
</html>

For more information send a message to info at phpclasses dot org.