Initial commit

This commit is contained in:
Romain de Laage 2020-12-15 11:18:07 +01:00
commit 7f5330ba7c
4 changed files with 73 additions and 0 deletions

25
README.md Normal file
View File

@ -0,0 +1,25 @@
# Upload file with webbrowser using python CGI
NGINX :
```
server {
listen 80;
server_name example.com;
location / {
root <your folder>/static;
autoindex on;
index index.html;
}
location ~ ^/cgi {
root <your folder>/cgi;
rewrite ^/cgi/(.*) /$1 break;
include fastcgi_params;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param SCRIPT_FILENAME <your folder>/cgi$fastcgi_script_name;
}
}
```

34
cgi/truc Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/python
import cgi, os
import cgitb
cgitb.enable()
form = cgi.FieldStorage()
print("Content-type: text/html")
print("")
print('<html>')
print('<head>')
print('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">')
print('<title>File upload</title>')
print('</head>')
print('<body>')
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('</body>')
print('</html>')

13
static/index.html Executable file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<h1>Upload form</h1>
<form enctype = "multipart/form-data" method="post" action="cgi/truc">
<input type="file" name="filename"><br>
<input type="submit">
</form>
</body>
</html>

1
uploads/README.md Normal file
View File

@ -0,0 +1 @@
Here are uploaded files