我正在使用 jquery+ajax 将文件传输到服务器。在服务器中,我有一个 python 脚本,我将其复制到下面,它只是获取文件并将其写入磁盘。该脚本适用于小于 1 Kby 的字节,但对于较大的文件,它会引发异常: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,)