teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

割愛させていただいていたCODEの部分も表示させていただきました

2017/10/02 13:20

投稿

kitm
kitm

スコア46

title CHANGED
File without changes
body CHANGED
@@ -22,4 +22,50 @@
22
22
  画像を表示したいので"Content-type"を"image/jpeg"にすべきだとは思ったのですが、そのようにすると画面が真っ黒になってしまいます。また、"Content-type"を"text/html"にすると、画像は表示されず英数字が長々と表示されます。
23
23
 
24
24
  ご助力いただけますと幸いでございます。
25
- 何卒よろしくお願いいたします。
25
+ 何卒よろしくお願いいたします。
26
+
27
+ ----------------------------------------------------
28
+
29
+ 割愛させていただいていた部分のCODEも表示させていただきました。
30
+ ```python
31
+ #!/usr/bin/env python
32
+ # -*- coding:utf-8 -*-
33
+ import cgi
34
+ import cgitb
35
+ import os, sys
36
+ cgitb.enable()
37
+
38
+ try:
39
+ import msvcrt
40
+ msvcrt.setmode(0, os.O_BINARY)
41
+ msvcrt.setmode(1, os.O_BINARY)
42
+ except ImportError:
43
+ pass
44
+
45
+ result = 'DUMMY'
46
+ form = cgi.FieldStorage()
47
+ #if form.has_key('file'):
48
+ if 'file' in form:
49
+ item = form['file']
50
+ if item.file:
51
+ # fout = file(os.path.join('/tmp', item.filename), 'wb')
52
+ fout = open(os.path.join('C:\server\cgi-bin\write', item.filename), 'wb')
53
+ while True:
54
+ chunk = item.file.read(1000000)
55
+ if not chunk:
56
+ break
57
+
58
+ fout.write(chunk)
59
+ fout.close()
60
+ result = 'upload is done'
61
+ #result = "アップロード"
62
+
63
+ f = open("hosi.jpg","rb")
64
+ print("Content-Type: text/html")
65
+ # print("Content-Type: image/jpeg")
66
+ print("")
67
+ print("<html><body>")
68
+ print(f.read())
69
+ print(result)
70
+ print("</body><html>")
71
+ ```