😃 Hello,
I am working on a function for a client login site and I am a bit confuzzed about how to go about making one of the most important features! Lemme give you the scenario
An employee here creates an account for his/her client (username, password included in this process) and upon submission of that form the account gets created. Their user and pass gets stored in a database called users. Add to it that a directory gets created based off of the clients username after the form is submitted (using mkdir) under a folder called usrfiles. So in essence, when that client logs in they can also see what is in their folder.
I am passing the following session variable all over this site so each users info stays confidential to their eyes only.
session_start();
header("Cache-control: private"); // IE 6 Fix.
$user_name = $_SESSION['user_name'];
require '../../globals/dbconnect.php';
'user_name' will be the same name as the clients user and folder the employee created.
Should the users table store some kind of value regarding this directory? If so, how and what?
On the page that displays the folder contents how would it connect to just that folder?
I have a script that works for displaying folder contents, but I can't figure out how to tell it to just look at one particular folder under this criteria
Heres the script
clearstatcache();
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != substr($PHP_SELF, -(strlen($PHP_SELF) - strrpos($PHP_SELF, "/") - 1))) {
if (filetype($file) == "dir") {
//SET THE KEY ENABLING US TO SORT
$n++;
if($_REQUEST['sort']=="date") {
$key = filemtime($file) . ".$n";
}
else {
$key = $n;
}
$dirs[$key] = $file . "/";
}
else {
//SET THE KEY ENABLING US TO SORT
$n++;
if($_REQUEST['sort']=="date") {
$key = filemtime($file) . ".$n";
}
elseif($_REQUEST['sort']=="size") {
$key = filesize($file) . ".$n";
}
else {
$key = $n;
}
$files[$key] = $file;
}
}
}
closedir($handle);
}
#USE THE CORRECT ALGORITHM AND SORT OUR ARRAY
if($_REQUEST['sort']=="date") {
@ksort($dirs, SORT_NUMERIC);
@ksort($files, SORT_NUMERIC);
}
elseif($_REQUEST['sort']=="size") {
@natcasesort($dirs);
@ksort($files, SORT_NUMERIC);
}
else {
@natcasesort($dirs);
@natcasesort($files);
}
#ORDER ACCORDING TO ASCENDING OR DESCENDING AS REQUESTED
if($_REQUEST['order']=="desc" && $_REQUEST['sort']!="size") {$dirs = array_reverse($dirs);}
if($_REQUEST['order']=="desc") {$files = array_reverse($files);}
$dirs = @array_values($dirs); $files = @array_values($files);
echo "<table width=\"375\" border=\"0\" cellspacing=\"0\" align=\"left\"><td colspan=\"1\">";
if($_REQUEST['sort']!="name") {
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=name&order=asc\">";
}
else {
if($_REQUEST['order']=="desc") {#
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=name&order=asc\">";
}
else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=name&order=desc\">";
}
}
echo "File</td><td width=\"50\"></a>";
if($_REQUEST['sort']!="size") {
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=size&order=asc\">";
}
else {
if($_REQUEST['order']=="desc") {#
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=size&order=asc\">";
}
else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=size&order=desc\">";
}
}
echo "Size</td><td width=\"120\" nowrap></a>";
if($_REQUEST['sort']!="date") {
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=date&order=asc\">";
}
else {
if($_REQUEST['order']=="desc") {#
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=date&order=asc\">";
}
else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=date&order=desc\">";
}
}
echo "Date Modified</a></td></tr>";
$arsize = sizeof($dirs);
for($i=0;$i<$arsize;$i++) {
echo "\t\t<td><a href=\"" . $dirs[$i] . "\">" . $dirs[$i] . "</a></td>";
echo "\t\t<td width=\"50\" align=\"left\">-</td>";
echo "\t\t<td width=\"120\" align=\"left\" nowrap>" . date ("M d Y h:i:s A", filemtime($dirs[$i])) . "</td>";
echo "\t</tr>";
}
$arsize = sizeof($files);
for($i=0;$i<$arsize;$i++) {
switch (substr($files[$i], -3)) {
}
echo "\t\t<td><a href=\"" . $files[$i] . "\">" . $files[$i] . "</a></td>\r\n";
echo "\t\t<td width=\"50\" align=\"left\">" . round(filesize($files[$i])/1024) . "KB</td>\r\n";
echo "\t\t<td width=\"120\" align=\"left\" nowrap>" . date ("M d Y h:i:s A", filemtime($files[$i])) . "</td>\r\n";
echo "\t</tr>\r\n";
}
echo "</table>";
Suggestions from any of the great minds in here???? 😕