Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set cookie to realize file upload

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to set cookie to achieve file upload", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to set cookie to achieve file upload" bar!

File upload instance

HTML sets the form for uploading files to set the enctype attribute to multipart/form-data. The code is as follows:

Rookie course (runoob.com)

Select the file:

The save_file.py script file code is as follows:

Example

#! / usr/bin/python3

Import cgi, os

Import cgitb; cgitb.enable ()

Form = cgi.FieldStorage ()

# get the file name

Fileitem = form ['filename']

# check whether the file is uploaded

If fileitem.filename:

# set file path

Fn = os.path.basename (fileitem.filename)

Open ('/ tmp/' + fn, 'wb') .write (fileitem.file.read ())

Message = 'File' + fn +'"uploaded successfully'

Else:

Message = 'File not uploaded'

Print ("\

Content-Type: text/html\ n

Rookie course (runoob.com)

% s

""% (message,)

Save the above code to save_file.py and modify the save_file.py permissions:

Chmod 755 save_file.py

The above cookie settings demonstrate that the Gif is as follows:

If you are using Unix/Linux, you must replace the file delimiter. Under window, you only need to use the open () statement:

Fn = os.path.basename (fileitem.filename.replace ("\", "/")) Thank you for your reading. The above is the content of "how to set cookie to upload files". After the study of this article, I believe you have a deeper understanding of how to set cookie to achieve file upload, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report