i am building a basic filemanager just for learning purpose.
how this sytem works: 1.user registration. while user fill registration form a directory created with a unique name. this name also store in database. 2.User login and access files and folders created by user.
but i faced a problem here. if anyone know the name of folder name and file paths (Can get from URL).
I want to make it secure. only loggedin user can access these files and folders (Who create the folders and files). Register.php file :
<?php
if(mysql_query("INSERT INTO user (UserId,FirstName,LastName,UserDirectory,Email,Password,Gender,dob,ipaddress,dateTime) VALUES('$userid','$fname','$lname','$dir','$email','$upass','$gender','$dob','$ipaddress','$datetime')"))
{ mkdir("file/$dir");
mkdir ("file/$dir/");
header("location:dir.php");
} ?>
dir.php file
<?php
session_start();
include_once 'dbconnect.php';
if(!isset($_SESSION['user']))
{
header("Location: index.php");
}
$id = $_SESSION['user'];
//echo $id;
$res=mysql_query("SELECT * FROM user where UserId = '$id' ");
if(mysql_num_rows($res) > 0){ // if one or more rows are returned do following
while($result = mysql_fetch_array($res)){
?>
<?php { { ?>
<?php //path to directory to scan
$directory = "file/$mydir";
//get all files in specified directory
$files = glob($directory . "*");
//print each file name
foreach($files as $file)
{
//check to see if the file is a folder/directory
if(is_dir($file))
{ ?>
<a href="<?php echo $file; ?>"> <br><?php echo $mydir; ?> </a> <?php
}
}?>
so if a user loggedin can easily access other users file by just type the file path. Means personalised folders and files on lye creator of a file or folder can edit/ view files . Request : this system is just for only learning purpose and i just want to learn this task. so if you dont have solution related this please dont comment about mysqli and PDO Comments. Thanks in Advance :)