私はLPTHW ex51をZed shaw http://learnpythonthehardway.org/book/ex51.htmlに従っていて、web.pyで彼の勉強訓練をしていました。私はweb.pyの初心者で、Webページ形式で画像をアップロードしてからローカルフォルダに保存しました。問題は、私が保存したそれぞれのイメージであり、以前のものと置き換えられます。また、サーバー上に複数の画像をアップロードしてそれらをすべて保存する方法については理解できません。ここでweb.pyで複数のファイルをアップロードしてディスクに保存するには?
はapp.pyで私のクラスのアップロードです:
class Upload(object):
def GET(self):
web.header("Content-Type","text/html; charset=utf-8")
return render.upload()
def POST(self):
x= web.input(myfile={})
filedir= "C:/Users/tejas/Documents/filesave"
if 'myfile' in x:
fout = open(filedir + '/' + 'myfile.jpg', 'wb') # creates the file where the uploaded file should be stored
fout.write(x.myfile.file.read()) # writes the uploaded file to the newly created file.
fout.close() # closes the file, upload complete
return "Success! Your image has been saved in the given folder."
raise web.seeother('/upload')
とupload.htmlフォーム - 私のアップロード:
<html>
<head><title>
<div id="header" <h1 style="color:blue;">Upload image file</h1><div/>
</title></head>
<body background-color=light-blue,font-family=verdana,font-size=100%;>
<form method="POST" enctype="multipart/form-data" action="">
<input type="file" name="myfile"/>
<br/> <br/><br/>
<input type="submit"/>
</form>
</body>
</html>
私は、同様の質問のために多くのことを探してみましたが、PHPのすべての私はコードと同様のものを試してみましたが、うまく動作しませんでした。コードを改善するための提案はありますか?
ありがとうございます。あなたの提案はそれを解決しました。 –
ありがとう – sachgits