简体   繁体   English

如何下载位于Web服务器CGI-bin文件夹中的文件?

[英]How to download a file located in web server CGI-bin folder?

I am creating a web application via python cgi . 我正在通过python cgi创建一个Web应用程序。 then after execute the cgi script , sqlite and mysql database files buildup in cgi-bin folder. 然后在执行cgi脚本后,在cgi-bin文件夹中建立sqlite和mysql数据库文件。 thus i want to grant download it for users. 因此,我想为用户授予下载权限。 but cgi-bin folder's files only for execute. 但是cgi-bin文件夹的文件仅供执行。 so how can i do it? 那我该怎么办呢?

which kind of script (php,perl,javascript,python etc.) can i use for download this generated database files in cgi-bin ? 我可以使用哪种脚本 (php,perl,javascript,python等)在cgi-bin中 下载此生成的数据库文件?

I haven't any experience with a real web hosting server! 我没有使用真正的虚拟主机服务器的经验!

You can use something like that with your cgi function. 您可以在cgi函数中使用类似的方法。 After you recieve a request you run that function: 收到请求后,您可以运行该功能:

import os
def return_file(name):
    filepath = os.path.join('/path/to/your/cgi-bin', name)
    if os.path.isfile(filepath):
        return open(filepath, 'b').read()

It will return content of your file in binary mode and you'll can return it as any MIME-format you want. 它将以二进制模式返回文件的内容,并且您可以将其返回为所需的任何MIME格式。

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

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