parent
a4a0968248
commit
fe202c017a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,52 @@
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog
|
||||
def login_1():
|
||||
|
||||
new_window = tk.Tk()
|
||||
new_window.title("欢迎来到登陆成功后的界面")
|
||||
new_window.geometry("300x200")
|
||||
|
||||
# 显示登陆成功的消息
|
||||
new_label = tk.Label(new_window, text="登陆成功!")
|
||||
new_label.pack()
|
||||
|
||||
button_frame = tk.Frame(new_window)
|
||||
button_frame.pack()
|
||||
|
||||
upload_button = tk.Button(button_frame, text="上传文件", command=upload_file)
|
||||
download_button = tk.Button(button_frame, text="下载文件", command=download_file)
|
||||
delete_button = tk.Button(button_frame, text="删除文件", command=delete_file)
|
||||
|
||||
# 使用grid()布局管理器在button_frame内
|
||||
upload_button.grid(row=4, column=0,padx=10, pady=10)
|
||||
download_button.grid(row=4, column=3,padx=10, pady=10)
|
||||
delete_button.grid(row=4, column=6,padx=10, pady=10)
|
||||
|
||||
# 退出按钮
|
||||
exit_button = tk.Button(new_window, text="返回", command=new_window.destroy)
|
||||
exit_button.pack()
|
||||
|
||||
new_window.mainloop()
|
||||
|
||||
|
||||
|
||||
def upload_file():
|
||||
|
||||
selected_file_path = filedialog.askopenfilename()
|
||||
new_window = tk.Tk()
|
||||
new_window.title("欢迎来到上传界面")
|
||||
new_window.geometry("600x200")
|
||||
# 更新界面,显示选定的文件路径
|
||||
selected_file_label = tk.Label(new_window, text=f"选定文件: {selected_file_path}")
|
||||
selected_file_label.pack()
|
||||
|
||||
new_window.mainloop()
|
||||
|
||||
|
||||
def download_file():
|
||||
return None
|
||||
|
||||
|
||||
def delete_file():
|
||||
return None
|
||||
|
@ -0,0 +1,38 @@
|
||||
import tkinter as tk
|
||||
from sql import *
|
||||
def register():
|
||||
|
||||
global register_view
|
||||
global username_entry, password_entry
|
||||
register_view = tk.Tk()
|
||||
register_view.title("欢迎来到注册界面")
|
||||
register_view.geometry("300x200")
|
||||
|
||||
username_label = tk.Label(register_view, text="用户名:")
|
||||
username_label.pack()
|
||||
username_entry_1 = tk.Entry(register_view)
|
||||
username_entry_1.pack()
|
||||
|
||||
password_label = tk.Label(register_view, text="密码:")
|
||||
password_label.pack()
|
||||
password_entry_1 = tk.Entry(register_view)
|
||||
password_entry_1.pack()
|
||||
|
||||
register_button = tk.Button(register_view, text="注册", command=register_0)
|
||||
register_button.pack()
|
||||
|
||||
back_button = tk.Button(register_view, text="返回", command=register_view.destroy)
|
||||
back_button.pack()
|
||||
|
||||
register_view.mainloop()
|
||||
|
||||
def register_0():
|
||||
entered_username = username_entry.get()
|
||||
entered_password = password_entry.get()
|
||||
if query_user(entered_username) is not None:
|
||||
erro_label = tk.Label(register_view, text="用户名已存在")
|
||||
erro_label.pack()
|
||||
else:
|
||||
add_user(entered_username, entered_password)
|
||||
ok_label = tk.Label(register_view, text="注册成功")
|
||||
ok_label.pack()
|
@ -1,25 +1,69 @@
|
||||
from flask import Flask, request, render_template
|
||||
import pymysql
|
||||
import os
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
UPLOAD_FOLDER = 'path_to_your_upload_folder'
|
||||
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
||||
def create_connection(host, user, password, db):
|
||||
connection = None
|
||||
try:
|
||||
connection = pymysql.connect(
|
||||
host=host,
|
||||
user=user,
|
||||
password=password,
|
||||
db=db,
|
||||
charset='utf8mb4',
|
||||
cursorclass=pymysql.cursors.DictCursor
|
||||
)
|
||||
print("Connection to MySQL DB successful")
|
||||
except pymysql.MySQLError as e:
|
||||
print(f"The error '{e}' occurred")
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
return connection
|
||||
|
||||
@app.route('/upload', methods=['POST'])
|
||||
def upload_file():
|
||||
if 'file' not in request.files:
|
||||
return 'No file part'
|
||||
file = request.files['file']
|
||||
if file.filename == '':
|
||||
return 'No selected file'
|
||||
if file:
|
||||
file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename))
|
||||
return 'File uploaded successfully'
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
def upload_file_to_db(connection, file_path):
|
||||
if not os.path.exists(file_path):
|
||||
print("File does not exist.")
|
||||
return
|
||||
|
||||
try:
|
||||
with open(file_path, 'rb') as file:
|
||||
# 读取文件二进制内容
|
||||
file_content = file.read()
|
||||
|
||||
cursor = connection.cursor()
|
||||
sql_query = """
|
||||
INSERT INTO file_storage (file_name, file_content)
|
||||
VALUES (%s, %s)
|
||||
"""
|
||||
# 获取文件名
|
||||
file_name = os.path.basename(file_path)
|
||||
# 执行SQL语句
|
||||
cursor.execute(sql_query, (file_name, pymysql.Binary(file_content)))
|
||||
connection.commit()
|
||||
print(f"File {file_name} has been uploaded successfully.")
|
||||
except pymysql.MySQLError as e:
|
||||
print(f"Error uploading file: {e}")
|
||||
|
||||
|
||||
# 数据库连接配置
|
||||
host = 'localhost'
|
||||
database = 'file'
|
||||
user = 'root'
|
||||
password = '123456'
|
||||
|
||||
# 文件路径
|
||||
file_path = 'file_paths.txt'
|
||||
|
||||
# 创建数据库连接
|
||||
conn = create_connection(host, user, password, database)
|
||||
|
||||
if conn is not None:
|
||||
# 上传文件到数据库
|
||||
upload_file_to_db(conn, file_path)
|
||||
else:
|
||||
print("Failed to connect to the database.")
|
||||
|
||||
# 关闭连接(如果打开)
|
||||
if conn:
|
||||
conn.close()
|
||||
|
||||
|
Loading…
Reference in new issue