Python 文件上传脚本无法运行

2024-06-24 13:08:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码:

#! /usr/bin/python
import cgi
import os
import shutil
from stegano import lsb

import cgitb
cgitb.enable()

HTML_HEADER = 'Content-type: text/html'

HEAD = '''
<!DOCTYPE html>
<html lang='en'>
    <head>
          <meta charset="UTF-8">
          <title>Success</title>
    </head>
    <body>
'''

END = '''
    </body>
</html>    
'''

def main():
        print HTML_HEADER
        print HEAD
        data = cgi.FieldStorage()
        filed = data['file'].value
        fileds = data['file']
        if filed.endswith('.jpg') or filed.endswith('.png') or filed.endswith('.jpeg') or filed.endswith('.tiff') and filed.count('/') == -1:
            #d = open('hello.txt', 'w')
            # d.write(filed)
            # d.close()
            os.chdir('files')
            with open(filed, 'wb') as fout:
                shutil.copyfileobj(fileds.file, fout, 100000)
        os.chdir('../')
        '''
        sec = lsb.hide(filed, data['message'].value)
        sec.save(filed)
        print "Successfully generated."
        '''
        print END

main()    

发生的情况是,我没有遇到任何错误(cgitb没有发现任何错误),但是,当我转到应该包含文件的目录时,它没有包含任何内容。我让它工作了一次,但当添加额外的东西失败了,我不能让它再次工作。我看到上传。。。在浏览器底部也有一次,但在目录中看不到任何文件。我很确定这是我犯的一个愚蠢的错误,但经过2个小时的搜索和测试,我没有看到它


Tags: orimportdataoshtml错误filecgi