home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / files / do_file_aed.php < prev    next >
Encoding:
PHP Script  |  2003-12-09  |  1.6 KB  |  69 lines

  1. <?php /* FILES $Id: do_file_aed.php,v 1.7 2003/12/09 00:09:56 gregorerhardt Exp $ */
  2. //addfile sql
  3. $file_id = intval( dPgetParam( $_POST, 'file_id', 0 ) );
  4. $del = intval( dPgetParam( $_POST, 'del', 0 ) );
  5. $obj = new CFile();
  6.  
  7. if (!$obj->bind( $_POST )) {
  8.     $AppUI->setMsg( $obj->getError(), UI_MSG_ERROR );
  9.     $AppUI->redirect();
  10. }
  11.  
  12. // prepare (and translate) the module name ready for the suffix
  13. $AppUI->setMsg( 'File' );
  14. // delete the file
  15. if ($del) {
  16.     $obj->load( $file_id );
  17.     if (($msg = $obj->delete())) {
  18.         $AppUI->setMsg( $msg, UI_MSG_ERROR );
  19.         $AppUI->redirect();
  20.     } else {
  21.         $AppUI->setMsg( "deleted", UI_MSG_ALERT, true );
  22.         $AppUI->redirect( "m=files" );
  23.     }
  24. }
  25.  
  26. set_time_limit( 600 );
  27. ignore_user_abort( 1 );
  28.  
  29. //echo "<pre>";print_r($_POST);echo "</pre>";die;
  30.  
  31. $upload = null;
  32. if (isset( $_FILES['formfile'] )) {
  33.     $upload = $_FILES['formfile'];
  34.  
  35.     if ($upload['size'] < 1) {
  36.         if (!$file_id) {
  37.             $AppUI->setMsg( 'Upload file size is zero. Process aborted.', UI_MSG_ERROR );
  38.             $AppUI->redirect();
  39.         }
  40.     } else {
  41.  
  42.     // store file with a unique name
  43.         $obj->file_name = $upload['name'];
  44.         $obj->file_type = $upload['type'];
  45.         $obj->file_size = $upload['size'];
  46.         $obj->file_date = db_unix2dateTime( time() );
  47.         $obj->file_real_filename = uniqid( rand() );
  48.  
  49.         $res = $obj->moveTemp( $upload );
  50.         if (!$res) {
  51.             $AppUI->setMsg( 'File could not be written', UI_MSG_ERROR );
  52.             $AppUI->redirect();
  53.         }
  54.         $obj->indexStrings();
  55.     }
  56. }
  57.  
  58. if (!$file_id) {
  59.     $obj->file_owner = $AppUI->user_id;
  60. }
  61.  
  62. if (($msg = $obj->store())) {
  63.     $AppUI->setMsg( $msg, UI_MSG_ERROR );
  64. } else {
  65.     $AppUI->setMsg( $file_id ? 'updated' : 'added', UI_MSG_OK, true );
  66. }
  67. $AppUI->redirect();
  68. ?>
  69.