在我的函数中,我正在下载一个将下载保存到日志文件的文件.每当我尝试下载上传的Excel文件时,Excel都会声明它已损坏.我的本地副本工作正常.这是我的download.php:
<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
sec_session_start();
ob_start();
?>
<?php if (login_check($mysqli) == true) :?>
<?php
$logFile = "download.log";
$directory = "./downloads/";
date_default_timezone_set('America/New_York');
$filename = $_GET['file'];
$path = "$directory$filename";
if(file_exists($path) AND substr_count($filename,"/") == "0") {
if (isset($logFile)) {
$downloadLogRecord = $filename." || ".$_SESSION['name']." || ".$_SESSION['username']." || ".$_SERVER['REMOTE_ADDR']." || ".date('Y-m-d H:i:s')."\r\n";
@file_put_contents($logFile,$downloadLogRecord,FILE_APPEND|LOCK_EX);
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Length: ".filesize($path));
readfile("$path");
}
?>
<?php else : ?>
<p>
<span class="error">You are not authorized to access this page.</span> Please <a href="index.php">login</a>.
</p> …Run Code Online (Sandbox Code Playgroud) 我最近试图回到Django,但是在尝试为练习创建登录页面时遇到了一些问题.我收到错误"登录需要1个参数(2个给定)",我不知道为什么.这是我的views.py:
from django.shortcuts import render_to_response
from django.contrib.auth import authenticate, login
from django.template import RequestContext
def login(request):
state = "Please log in below..."
username = password = ''
if request.POST:
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
state = "You're successfully logged in!"
else:
state = "Your account is not active, please contact the site admin."
else:
state = "Your username and/or password were incorrect."
return render_to_response('login.html',{'state':state, 'username': username},context_instance=RequestContext(request)) …Run Code Online (Sandbox Code Playgroud)