jquery+ajax を使用してファイルをサーバーに転送しています。サーバーには、ファイルを取得してディスクに書き込むだけのPythonスクリプトがあり、これを以下にコピーします。スクリプトは 1 KB 未満のバイトに対しては完璧に機能しますが、それより大きいファイルに対しては例外をスローします: OSError: [Errno 13] Permission denied
なぜこれが起こるのですか?サーバーにアクセスできません。サーバー管理者に何か質問する必要がありますか?
#!/usr/local/bin/python
import cgi, os
import cgitb; cgitb.enable()
try: # Windows needs stdio set for binary mode.
import msvcrt
msvcrt.setmode (0, os.O_BINARY) # stdin = 0
msvcrt.setmode (1, os.O_BINARY) # stdout = 1
except ImportError:
pass
form = cgi.FieldStorage()
# A nested FieldStorage instance holds the file
fileitem = form['photo']
# Test if the file was uploaded
fn = os.path.basename(fileitem.filename)
# strip leading path from file name to avoid directory traversal attacks
if fileitem.filename:
fn = fileitem.filename
open('fotos/' + fn, 'wb').write(fileitem.file.read())
message = 'The file "' + fn + '" was uploaded successfully'
else:
message = 'No file was uploaded'
print """\
Content-Type: text/html\n
<html><body>
<p>%s</p>
</body></html>
""" % (message,)