繁体   English   中英

上载wav文件并使用python保存在目录中

[英]Upload wav file and save in directory using python

这是我的数据库模型

     db.define_table('manage_music_file',                                                                                                           
     Field('action_is', requires=IS_IN_SET(('Insert', 
               'Remove')),notnull=True, default='Insert'),                                   
     Field('wav_file', 'upload', comment='Please upload your .wav 
                file',requires=IS_NOT_EMPTY()           
     )

这是我的控制器

    def index(): 
       form = SQLFORM(db.manage_music_file)  
         #return dict(form=form)
       if form.process().accepted:
          logger.debug(('here we ahve a form',form))
          errors = []
          if form.vars['action_is'] == 'Insert':
             logger.debug(('where file need to place'))
             if not form.vars['wav_file']:
                  errors.append('No file given')
             return 'No file given'
          else:
            dirname='/var/lib/asterisk/sounds/musiconhold'
            logger.debug(('where file need to place', dirname))
            import os.path
            completeName = os.path.join(dirname, form.vars.wav_file)
            file1 = open(completeName, "a")
            file1.close()

       return dict(form=form)

我正在上载中发送wav文件A.wav,但是我在目录中以这种格式接收文件

      manage_music_file.wav_file.a70701e297ffec7a.412e776176.wav 

我也要在目录中使用相同的名字A.wav

      A.wav 

Hamza,web2py将这些文件重命名为一种安全措施,以帮助防止目录遍历攻击。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM