OLD | NEW |
1 <?php | 1 <?php |
2 if (strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data; boundary=') != 0) { | 2 if (strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data; boundary=') != 0) { |
3 echo 'Invalid Content-Types.'; | 3 echo 'Invalid Content-Types.'; |
4 return; | 4 return; |
5 } | 5 } |
6 | 6 |
7 $values = array(); | 7 $values = array(); |
8 | 8 |
9 foreach ($_POST as $key => $value) { | 9 foreach ($_POST as $key => $value) { |
10 $values[] = "$key=$value"; | 10 $values[] = "$key=$value"; |
11 } | 11 } |
12 | 12 |
13 foreach ($_FILES as $key => $value) { | 13 foreach ($_FILES as $key => $value) { |
14 $file = $_FILES[$key]; | 14 $file = $_FILES[$key]; |
15 if ($file['error']) { | 15 if ($file['error']) { |
16 echo 'Upload file error: ' . $file['error']; | 16 echo 'Upload file error: ' . $file['error']; |
17 return; | 17 return; |
18 } else { | 18 } else { |
19 $fp = fopen($file['tmp_name'], 'r'); | 19 $fp = fopen($file['tmp_name'], 'r'); |
20 if ($fp) { | 20 if ($fp) { |
21 $content = fread($fp, $file['size']); | 21 $content = $file['size'] > 0 ? fread($fp, $file['size']) : ""; |
22 fclose($fp); | 22 fclose($fp); |
23 } | 23 } |
24 $values[] = $key . '=' . $file['name'] . ':' . $file['type'] . ':' . $co
ntent; | 24 $values[] = $key . '=' . $file['name'] . ':' . $file['type'] . ':' . $co
ntent; |
25 } | 25 } |
26 } | 26 } |
27 | 27 |
28 echo join('&', $values); | 28 echo join('&', $values); |
29 ?> | 29 ?> |
OLD | NEW |