From 7f5330ba7c171a46a8290310ad2d8e92ecf25ee5 Mon Sep 17 00:00:00 2001 From: romain de laage Date: Tue, 15 Dec 2020 11:18:07 +0100 Subject: [PATCH] Initial commit --- README.md | 25 +++++++++++++++++++++++++ cgi/truc | 34 ++++++++++++++++++++++++++++++++++ static/index.html | 13 +++++++++++++ uploads/README.md | 1 + 4 files changed, 73 insertions(+) create mode 100644 README.md create mode 100755 cgi/truc create mode 100755 static/index.html create mode 100644 uploads/README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..a289316 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# Upload file with webbrowser using python CGI + +NGINX : + +``` +server { + listen 80; + server_name example.com; + + location / { + root /static; + autoindex on; + index index.html; + } + + location ~ ^/cgi { + root /cgi; + rewrite ^/cgi/(.*) /$1 break; + + include fastcgi_params; + fastcgi_pass unix:/var/run/fcgiwrap.socket; + fastcgi_param SCRIPT_FILENAME /cgi$fastcgi_script_name; + } +} +``` diff --git a/cgi/truc b/cgi/truc new file mode 100755 index 0000000..4c34fc8 --- /dev/null +++ b/cgi/truc @@ -0,0 +1,34 @@ +#!/usr/bin/python + +import cgi, os +import cgitb + +cgitb.enable() + +form = cgi.FieldStorage() + +print("Content-type: text/html") +print("") + +print('') +print('') +print('') +print('File upload') +print('') +print('') + +print("Salut") + +fileitem = form['filename'] + + +if fileitem.filename: + print("Uploaded file : "+fileitem.filename) + filename = os.path.basename(fileitem.filename) + uploadedfile = open("../uploads/"+filename, 'wb') + uploadedfile.write(fileitem.file.read()) +else: + print("No file uploaded") + +print('') +print('') diff --git a/static/index.html b/static/index.html new file mode 100755 index 0000000..70eb213 --- /dev/null +++ b/static/index.html @@ -0,0 +1,13 @@ + + + + + + +

Upload form

+
+
+ +
+ + diff --git a/uploads/README.md b/uploads/README.md new file mode 100644 index 0000000..b067739 --- /dev/null +++ b/uploads/README.md @@ -0,0 +1 @@ +Here are uploaded files