Initial commit
This commit is contained in:
commit
7f5330ba7c
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
|
@ -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>')
|
|
@ -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>
|
|
@ -0,0 +1 @@
|
||||||
|
Here are uploaded files
|
Loading…
Reference in New Issue