pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

PHP pastebin - collaborative debugging tool View Help


Posted by Antonie Potgieter on Tue 20 Nov 16:23 (modification of post by Antonie Potgieter view diff)
report abuse | View followups from Anonymous and salim | download | new post

  1. <?php
  2.  
  3. //start a PHP session.
  4.  
  5. class Upload {
  6.  
  7.         //upload directory.
  8.         //make sure it exists
  9.         //chmod it to 0777 to be writable
  10.         var $upload_dir = "uploads/";
  11.  
  12.         //the name of the file.
  13.         var $name = '';
  14.        
  15.         //TMP name of the file on server.
  16.         var $tmp_name = '';
  17.        
  18.         //the size of the file.
  19.         //this is measured in bytes
  20.         var $size = '';
  21.        
  22.         //the mime type of the file.
  23.         //ex. image/png
  24.         var $type = '';
  25.        
  26.         //number of files uploaded so far.
  27.         var $count = 1;
  28.  
  29.         function Upload($file = array()) {
  30.                 //make sure that the file data is not empty.
  31.                 if (!empty($file)) {
  32.                         //loop the file array
  33.                         foreach ($file as $key => $val) {
  34.                                 $this -> {$key} = $val;
  35.                         }
  36.                        
  37.                         //execute the uploading method.
  38.                         $this -> upload_file();
  39.                 }
  40.         }
  41.        
  42.         function upload_file() {
  43.                 //make sure the the file has been uploaded
  44.                 if (is_uploaded_file($this -> tmp_name)) {
  45.                         //make sure that the file can be moved to the "upload_dir"
  46.                         if (move_uploaded_file($this -> tmp_name, $this -> upload_dir . $this -> name)) {
  47.                                 //increment the file count.
  48.                                 $newcount = (!isset($_SESSION['filecount'])) ? $this -> count : ($_SESSION['filecount'] + 1);
  49.                                 $_SESSION['files'][$newcount]['filename'] = $this -> name;
  50.                                 $_SESSION['files'][$newcount]['filesize'] = $this -> size;
  51.                                 $_SESSION['files'][$newcount]['filetype'] = $this -> type;
  52.                         } else {
  53.                                 //file could not be moved
  54.                                 return false;
  55.                         }
  56.                 } else {
  57.                         //file was not uploaded
  58.                         return false;
  59.                 }
  60.         }
  61. }
  62.  
  63. //get all the posted file data
  64. $file = $_FILES['Filedata'];
  65.  
  66. //initialize the Upload class.
  67. $upload = new Upload($file);
  68.  
  69. ?>
  70.  
  71. <?php
  72.  
  73. //custom variable passed to the flash application
  74. $customVariable = $_GET['customVariable'];
  75. //the number of files uploaded
  76. $totalFileCount = $_GET['totalFileCount'];
  77.  
  78. //loop the uploaded files.
  79. //this is received from the flash application
  80. for ($i = 0; $i < $totalFileCount; $i++) {
  81.         $files[$i] = array(
  82.                 'filename' => $_GET['filename' . $i],
  83.                 'filesize' => $_GET['filesize' . $i],
  84.                 'filetype' => $_GET['filetype' . $i],
  85.         );     
  86. }
  87.  
  88. //appand some text to our data.
  89. $data = "Custom Variable - " . $customVariable . "\n";
  90. $data .= "Total File Count - " . $totalFileCount . "\n";
  91.  
  92. foreach ($files as $fKey => $fVal) {
  93.         foreach ($files[$fKey] as $fKey2 => $fVal2) {
  94.                 $data .= $fKey2 . " no " . $fKey . " - " . $fVal2 . "\n";
  95.         }       
  96. }
  97.  
  98. //open a new log file.
  99. $fh = fopen("uploads/test_" . time() . ".txt", "w");
  100. //write the generated data to the file.
  101. fwrite($fh, $data);
  102. //close the log file handle
  103. fclose($fh);
  104.  
  105. //response for the flash application
  106. echo 'success';
  107.  
  108. ?>

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me