Hello, I created an html file with one and I want to select an image from a directory and after clicking on submit this image should be saved in another directory. Any help?
This is what I've tried so far ...
index.html
<form name="pyform" method="POST" action="upload.py">
<input type="file" name="image" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
upload.py
#!c:/Python34/python
# -*- coding: UTF-8 -*-
print("Content-Type: text/html")
print()
import cgi,cgitb
cgitb.enable()
form = cgi.FieldStorage()
file = form['image'].value
upload_dir = 'C:/wamp/www/upload/' # esse é o diretório onde vou salvar a imagem
f = open(upload_dir + file, 'w')
f.write(file)
f.close()
I noticed that after running the code, a file with the same image name is created, however, with size 0kb and can not be displayed.