登录后显示特定用户的下载文件的方法

问题描述 投票:1回答:2

我希望用户在登录后重定向到下载页面,用户可以下载admin-pre-uploaded文件。

我想在用户登录时显示一个pdf文件供下载。与用户1登录并重定向到他的下载或仪表板页面,其中file.pdf的简单下载链接正在等待他被点击。与user2 3等其他用户相同。不同的文件。我的客户想让他的用户能够下载他们的婚姻专辑的pdf。因此,他希望当客户登录时,它会转到可以下载其相册的页面。如何在登录时为每个用户设置自定义下载URL?

任何CMS或Wordpress或PHP脚本都是首选。

我尝试了https://userspice.com/但失败了。有什么办法吗?

php wordpress content-management-system modx
2个回答
1
投票

好现在你必须创建一个数据库和表:

1用户表 用户密码和用户名是否将被存储或存储 2.文件表 如果您的文件(pdf)将被存货或存货

创建数据库和表后,您将需要4个文件 download.php,form.php,connexion.php和get_file.php Download.php将内容如下:

<?php session_start ();?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Download</title>
</head>

<body> 

<?php 
    if(isset($_Post['user_name']) AND isset($_Post['password'])){
        //connexion to the data_base. I use PDO
        require'connexion.php';
//end of connexion to data_base

$c =$base->query("SELECT user, password FROM registred_user_tabe WHERE user='".strip_tags($_Post['user_name'])."' AND  user='".strip_tags($_Post['password'])."'");
$usertest =$c->fetch();

    if(!empty($usertest['user']) AND $usertest['user']==$_Post['user_name']){

        //NOW you creat the session login
    $_session['connected']['user_name']=$_Post['user_name'];
    $_session['connected']['password']=$_Post['password'];
    //Now redirect user to download page or show the link
    header('location: download.php');
    }



    }
    ;?>
<?php if(isset($_session['connected'])){
    //Require get_file.php IF SESSION USER EXIST...
    require'get_file.php'
    ;}else{
    //REQUIRE form.php IF WANT CONNEXION TO DOWNLOAD FILE...
        require'form.php'
    ;};?>
</body>
</html>

Form.php将内容如下:

<h1>Connexion requirer</h1><form action="" method="post" enctype="multipart/form-data" name="connect" target="_parent">
<label for="password"></label><input name="user_name" type="text" id="user_name" placeholder="Your User Name" /><br/>
<label for="password"></label><input name="password" type="password" id="password"  placeholder="Enter Password"/><br/><input name="send" type="submit" value="SEND" id="send" /></form>

Connexion.php将内容如下:

<?php $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$base = new PDO('mysql:host=localhost;dbname=your_data_base', 'the_user', 'Your_password', $pdo_options);
//end of connexion to data_base;?>

并且get_file.php将包含以下内容:

<?php 
//CONNEXION TO DATA BASE
require'connexion.php';
//LISTING ALL FILE OF USER TO DOWNLOAD
$file=$base->query("SELECT name_of_file FROM tabe_were_you_stock_file WHERE owner='".$_session['connected']['user_name']."'");
while($file_stocked =$file->fetch()){
 echo '<a href="get_file.php?id_of_file='.$file_stocked['name_of_file'].'">Download: '.$file_stocked['name_of_file'].'</a>';
;}
//END OF LISTING
//PHP IS WAITING FOR "id_of_file" TO DOWNLOAD IT
if(isset($_GET['id_of_file'])){
$that_file=htmlspecialchars($_GET['id_of_file']);

 $file = 'upload_dir/'.$that_file;

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}else{echo'<strong>Error:</strong> file not found...';}}

;?>

别担心,你的文件夹链接不会用这种方法显示,非常安全。

注意:您必须使用** phpmyadmin创建数据库(如果您没有)和您需要的表!**


0
投票

首先,您必须为您的项目使用会话。只有一个问题:您是否希望用户知道下载文件夹?

首先在一个用户可以登录的表单提交,在php中处理密码和用户名后如下:

<?php 
if(isset($_Post['user_name']) AND isset($_Post['password'])){
session_start ();
/*Now you make a SQL query to know if the user_name and passwor exist and they equal*/

if(sql_query_is_Ok){//NOW you creat the session login
$_session['connected']['user_name']=$_Post['user_name'];
$_session['connected']['password']=$_Post['password'];
//Now redirect user to download page
heade('location: url_where_file_can_bedownloade.php');
}



}
;>

在url_where_file_can_bedownloade.php中

<?php 
if(isset($_session['connected']['user_name']) AND isset($_session['connected']['password'])){

}else{exit('restricted area!!!');}

;?>

//页面的reste将显示该文件的链接

<a href="folder/Name_of_your_file.pdf">Download: Name_of_your_file.pdf</a>
© www.soinside.com 2019 - 2024. All rights reserved.