File: fcgi_test.php

package info (click to toggle)
golang-github-tomasen-fcgi-client 0.0~git20180423.2bb3d81-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104 kB
  • sloc: php: 60; makefile: 2
file content (79 lines) | stat: -rw-r--r-- 2,071 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php

ini_set("display_errors",1);

echo "resp: start\n";//.print_r($GLOBALS,1)."\n".print_r($_SERVER,1)."\n";

//echo print_r($_SERVER,1)."\n";

$length = 0;
$stat = "PASSED";

$ret = "[";

if (count($_POST) || count($_FILES)) {
  foreach($_POST as $key => $val) {
    $md5 = md5($val);
    
    if ($key != $md5) {
      $stat = "FAILED";
      echo "server:err ".$md5." != ".$key."\n";
    }
    
    $length += strlen($key) + strlen($val);
    
    $ret .= $key."(".strlen($key).") ";
  }
  $ret .= "] [";
  foreach ($_FILES as $k0 => $val) {

    $error = $val["error"];
    if ($error == UPLOAD_ERR_OK) {
      $tmp_name = $val["tmp_name"];
      $name = $val["name"];
      $datafile = "/tmp/test.go";
      move_uploaded_file($tmp_name, $datafile);
      $md5 = md5_file($datafile);

      if ($k0 != $md5) {
        $stat = "FAILED";
        echo "server:err ".$md5." != ".$key."\n";
      }      
      
      $length += strlen($k0) + filesize($datafile);
      
      unlink($datafile);
      $ret .= $k0."(".strlen($k0).") ";
    }
    else{
      $stat = "FAILED";
      echo "server:file err ".file_upload_error_message($error)."\n";
    }
  }
  $ret .= "]";
  echo "server:got data length " .$length."\n";
}


echo "-{$stat}-POST(".count($_POST).") FILE(".count($_FILES).")\n";

function file_upload_error_message($error_code) {
  switch ($error_code) { 
    case UPLOAD_ERR_INI_SIZE: 
    return 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; 
    case UPLOAD_ERR_FORM_SIZE: 
    return 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'; 
    case UPLOAD_ERR_PARTIAL: 
    return 'The uploaded file was only partially uploaded'; 
    case UPLOAD_ERR_NO_FILE: 
    return 'No file was uploaded'; 
    case UPLOAD_ERR_NO_TMP_DIR: 
    return 'Missing a temporary folder'; 
    case UPLOAD_ERR_CANT_WRITE: 
    return 'Failed to write file to disk'; 
    case UPLOAD_ERR_EXTENSION: 
    return 'File upload stopped by extension'; 
    default: 
    return 'Unknown upload error'; 
  } 
}