Get the App
SLTechnology News&Howtos  ›  Development  › 

How to set cookie to realize file upload

Shulou Source: shulou.com Published: 2022-06-01 01:33:21 09月12日 Update

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!

Tags: Files code learning content examples tutorials rookie tutorials rookie tutorials success delimiters that is attributes ideas situations file names articles more permissions knowledge knowledge points Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Microsoft Apple Huawei vpn