upload form submits delete_time to database
This commit is contained in:
parent
a760b40718
commit
88e462b0e0
28
fileHost.py
28
fileHost.py
|
@ -332,17 +332,35 @@ def index():
|
||||||
|
|
||||||
file = request.files.get('file')
|
file = request.files.get('file')
|
||||||
fname = secure_filename(file.filename)
|
fname = secure_filename(file.filename)
|
||||||
fdir = app.config.get("UPLOAD_DIR")
|
|
||||||
pre = get_rand_chars(8)
|
pre = get_rand_chars(8)
|
||||||
|
fdir = app.config.get("UPLOAD_DIR")
|
||||||
|
|
||||||
if request.form.get("randname") == "on":
|
if request.form.get("randname") == "on":
|
||||||
fname = pre + os.path.splitext(fname)[1]
|
fname = pre + os.path.splitext(fname)[1]
|
||||||
else:
|
else:
|
||||||
fname = pre + "_" + fname
|
fname = pre + "_" + fname
|
||||||
|
|
||||||
|
if request.form.get("delflag") == "on":
|
||||||
|
try:
|
||||||
|
delete_time = int(request.form.get("delnum"))
|
||||||
|
assert delete_time >= 1 and delete_time <= 59
|
||||||
|
except (ValueError, AssertionError):
|
||||||
|
return 'Invalid entry: "delnum=' + request.form.get("delnum") + '"'
|
||||||
|
del_dict = {"minute": 60, "hour": 3600, "day": 3600*24, "week": 3600*24*7}
|
||||||
|
try:
|
||||||
|
delete_time *= del_dict[request.form.get("deltype")]
|
||||||
|
except KeyError:
|
||||||
|
return 'Invalid entry: "deltype=' + request.form.get("deltype")+'"'
|
||||||
|
delete_time = int(time.time()) + delete_time
|
||||||
|
|
||||||
|
db_execute(
|
||||||
|
"INSERT INTO UPLOADS (filename, uploaded_by, delete_date)"
|
||||||
|
"VALUES (?,?,?)", (fname, username, delete_time))
|
||||||
|
else:
|
||||||
|
db_execute("INSERT INTO uploads (filename, uploaded_by) VALUES (?,?)",
|
||||||
|
(fname, username))
|
||||||
|
|
||||||
file.save(os.path.join(fdir, fname))
|
file.save(os.path.join(fdir, fname))
|
||||||
|
|
||||||
db_execute("INSERT INTO uploads (filename, uploaded_by) VALUES (?,?)",
|
|
||||||
(fname, username))
|
|
||||||
|
|
||||||
url = app.config.get("UPLOAD_URL") + fname
|
url = app.config.get("UPLOAD_URL") + fname
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
|
|
@ -11,13 +11,13 @@
|
||||||
<a href="{{ url_for('manage_uploads') }}">Manage Uploads</a><br />
|
<a href="{{ url_for('manage_uploads') }}">Manage Uploads</a><br />
|
||||||
<p>Select file to upload:
|
<p>Select file to upload:
|
||||||
<p><input type="file" name="file" required/><br />
|
<p><input type="file" name="file" required/><br />
|
||||||
<input type="checkbox" name="randname"/> Generate random filename.
|
<input type="checkbox" name="randname"/> Generate random filename.<br />
|
||||||
<p><input type="checkbox" name="delete"/> Delete this file in <input type="number" value="1"/>
|
<input type="checkbox" name="delflag"/> Delete this file in <input type="number" name="delnum" min="1" max="59" value="1"/>
|
||||||
<select>
|
<select name="deltype">
|
||||||
<option value="minute">Minute</option>
|
<option value="minute">Minute</option>
|
||||||
<option value="hour">Hour</option>
|
<option value="hour">Hour</option>
|
||||||
<option value="day">Day</option>
|
<option value="day" selected="selected">Day</option>
|
||||||
<option value="month">Month</option>
|
<option value="week">Week</option>
|
||||||
</select>
|
</select>
|
||||||
<p><input type="submit" value="Upload File" name="submit"/>
|
<p><input type="submit" value="Upload File" name="submit"/>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user