home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / sources / misc / attach.php next >
Encoding:
PHP Script  |  2002-06-12  |  2.7 KB  |  95 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > Attachment Handler module
  17. |   > Module written by Matt Mecham
  18. |   > Date started: 10th March 2002
  19. |
  20. |    > Module Version Number: 1.0.0
  21. +--------------------------------------------------------------------------
  22. */
  23.  
  24.  
  25. $idx = new attach;
  26.  
  27. class attach {
  28.  
  29.     
  30.     function attach()
  31.     {
  32.         global $ibforums, $DB, $std, $print, $skin_universal;
  33.         
  34.         $ibforums->input['id'] = preg_replace( "/^(\d+)$/", "\\1", $ibforums->input['id'] );
  35.         
  36.         if ($ibforums->input['id'] == "")
  37.         {
  38.             $std->Error( array( 'LEVEL' => 1, 'MSG' => 'missing_files' ) );
  39.         }
  40.         
  41.         if ($ibforums->input['type'] == 'post')
  42.         {
  43.             // Handle post attachments.
  44.             
  45.             $DB->query("SELECT pid, attach_id, attach_type, attach_file FROM ibf_posts WHERE pid='".$ibforums->input['id']."'");
  46.             
  47.             if ( !$DB->get_num_rows() )
  48.             {
  49.                 $std->Error( array( 'LEVEL' => 1, 'MSG' => 'missing_files' ) );
  50.             }
  51.             
  52.             $post = $DB->fetch_row();
  53.             
  54.             if ( $post['attach_id'] == "" )
  55.             {
  56.                 $std->Error( array( 'LEVEL' => 1, 'MSG' => 'missing_files' ) );
  57.             }
  58.             
  59.             $file = $ibforums->vars['upload_dir']."/".$post['attach_id'];
  60.             
  61.             if ( file_exists( $file ) and ( $post['attach_type'] != "" ) )
  62.             {
  63.                 // Update the "hits"..
  64.                 
  65.                 $DB->query("UPDATE ibf_posts SET attach_hits=attach_hits+1 WHERE pid='".$post['pid']."'");
  66.                 
  67.                 // Set up the headers..
  68.                 
  69.                 @header( "Content-Type: ".$post['attach_type']."\nContent-Disposition: inline; filename=\"".$post['attach_file']."\"\nContent-Length: ".(string)(filesize( $file ) ) );
  70.                 
  71.                 // Open and display the file..
  72.                 
  73.                 $fh = fopen( $file, 'rb' );  // Set binary for Win even if it's an ascii file, it won't hurt.
  74.                 fpassthru( $fh );
  75.                 @fclose( $fh );
  76.             }
  77.             else
  78.             {
  79.                 // File does not exist..
  80.                 $std->Error( array( 'LEVEL' => 1, 'MSG' => 'missing_files' ) );
  81.             }
  82.         }
  83.         
  84.     }
  85.         
  86.        
  87. }
  88.  
  89. ?>
  90.  
  91.  
  92.  
  93.  
  94.  
  95.