Tuesday 15 February 2011

python - Webpy uploading files, Understanding where does "imagename" come from? -


Using the webpage structure, I am uploading files to my server and work fine. My problem is that I am not sure where the specialty ' filename ' comes from? And how does it actually get the name of the file? This is the first time in a dictionary, right? I have also read some webpages but I did not find anything relevant. Here is some part of my code:

  class upload (object): def mill (self): return render .upload_form () def post (auto): update_form = web.input (file = {}} File_dir = '/ users / admin / developer / projects / pro / templates / img' if 'file in update_form': file_name = update_form.file.filename f_out = open (file_dir + '/' + file_name, 'w' ) F_out.write (update_form.file.file.read ()) f_out.close () Returns self GET ()   

Please refer to the line:

  file_name = update_form.file.filename # & lt; - what ???   

Any help would be appreciated, thanks!

When you upload a file, you must use the content type. In an html form you can set it as enctype = "multipart / form-data" attribute. The browser automatically adds file names to the request for file input. A raw request will look something like this:

 POST / upload HTTP / 1.1 host: example.org Content-Type: Multipart / Form-Data; Border = some external - solid content content: form-data; Name = "name"; File name = "filename.txt" content-type: file text / plain content .... -Somodiali -  

name is the name of the form element, and File name original file name.

as a default value in your code (see :), so that you later ask this information Able to If you do not use a default, the contents of the file are stored as simply as a string.

Keep in mind that the file name is user input and can do anything, so it should be senate! Anyone can upload a file like "../../../ some_directory / some_important_file" and thus overwrites or lets create a file anywhere where the server process does so Have the right to

No comments:

Post a Comment