Magento Expert Forum - Improve your Magento experience
-
tring to develop my own php based file manager here is my code help me
i'm able to display initial list but when clickking on any folder im getting a warning :
Warning: filemtime(): stat failed for
my code :
index.php
<html>
<head>
<title>Simple File Manager</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="C:\wamp\www\pfm\jquery\jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#foldername").focus();
/*$.ajax({
url:"firstget.php",
cache:false,
success:function(data)
{
$("#display").html(data);
}
});*/
$(".file").click(function(e)
{
e.preventDefault();
var element=$(this);
var file_id=element.attr("id");
//alert("The file or directory you selected is: "+ file_id);
var dataString = "file_id=" + file_id;
$.ajax({
type:"POST",
url:"read_contents.php",
data:dataString,
success:function(data)
{
$("#display").html(data);
}
});
});
});
</script>
<style type="text/css">
table
{
width:450px;
margin:0 auto;
border:3px double #000;
font-family:"courier new";
font-size:10pt;
}
table tr td
{
height:35px;
text-align:center;
}
table th
{
border-bottom:1px solid #000;
text-align:left;
padding-left:9px;
height:35px;
font-size:12pt;
line-height:35px;
}
#list
{
border:1px solid #6dcece;
width:800px;
margin:0 auto;
font-family:arial,"Calibri","times new roman";
box-shadow:0px 0px 5px #cacbcb;
border-radius:0px;
border-collapse:collapse;
background:rgba(255,255,255,0.5);
}
#list tr:last-child td
{
border-bottom:0px;
}
#list tr td:first-child:hover a,#list tr td:first-child:hover
{
background:#80a5b2;
color:#fff;
}
#list tr td
{
padding-left:11px;
text-align:left;
font-size:12pt;
height:35px;
border-bottom:1px solid #cacbcb;
border-collapse:collapse;
}
#list tr th
{
background:#6dcece;
color:#fff;
border-bottom:1px solid #6dcece;
}
#list td:nth-child(2),#list td:nth-child(3),#list td:nth-child(4),#list td:nth-child(5)
{
text-align:left;
width:100px;
font-size:10pt;
}
#list #php img
{
vertical-align:middle;
width:20px;
height:20px;
}
#list #gallery img
{
width:20px;
height:17px;
}
#list img
{
width:20px;
height:25px;
vertical-align:middle;
}
#list a
{
text-decoration:underline;
color:#000;
display:block;
height:35px;
line-height:35px;
padding-left:0px;
font-weight:bold;
}
#list img
{
margin-right:9px;
}
</style>
</head>
<body>
<form name="form1" method="post" action="create.php">
<table>
<tr><th colspan=2 align=center>Create folder using PHP</th></tr>
<tr>
<td>Enter folder to create</td>
<td><input type="text" name="foldername" id="foldername" autocomplete="off" required></td>
</tr>
<tr>
<td colspan=2 align=center><input type="submit" name="submit" id="submit" value="Create"></td>
</tr>
</table>
</form>
<div id="display">
<?php include 'firstget.php'; ?>
</div>
</body>
</html>
read_contents.php
<?php
function formatSizeUnits($bytes)
{
if ($bytes >= 1073741824)
{
$bytes = number_format($bytes / 1073741824, 2) . ' GB';
}
elseif ($bytes >= 1048576)
{
$bytes = number_format($bytes / 1048576, 2) . ' MB';
}
elseif ($bytes >= 1024)
{
$bytes = number_format($bytes / 1024, 2) . ' KB';
}
elseif ($bytes > 1)
{
$bytes = $bytes . ' Bytes';
}
elseif ($bytes == 1)
{
$bytes = $bytes . ' Byte';
}
else
{
$bytes = '0 Bytes';
}
return $bytes;
}
$file_id=$_POST['file_id'];
//$full_path = getcwd()."\\".$file_id;
$full_path="./".$file_id;
//$full_path = chdir($file_id);
//$full_path=$file_id."\\";
//$full_path=".\\".$file_id;
//$full_path=str_replace("C:\wamp\www","localhost",$ full_path);
//$full_path=str_replace("\\","/",$full_path);
echo $full_path;
$dir = opendir($full_path) or die("Unable to open directory");
if(opendir($full_path)){echo "<br/>directory opened";}
echo "<table id='list'><tr><th>Name</th><th>Date</th><th>Time</th><th>Size</th><th>Permissions</th></tr>";
while($file = readdir($dir))
{
date_default_timezone_set('Asia/Kolkata');
$moddate=date("d/m/Y",filemtime($file));
$modtime=date("h:i A",filemtime($file));
$size=filesize($file);
$convertedsize = formatSizeUnits($size);
$perms = fileperms($file);
if (($perms & 0xC000) == 0xC000) {
// Socket
$info = 's';
} elseif (($perms & 0xA000) == 0xA000) {
// Symbolic Link
$info = 'l';
} elseif (($perms & 0x8000) == 0x8000) {
// Regular
$info = '-';
} elseif (($perms & 0x6000) == 0x6000) {
// Block special
$info = 'b';
} elseif (($perms & 0x4000) == 0x4000) {
// Directory
$info = 'd';
} elseif (($perms & 0x2000) == 0x2000) {
// Character special
$info = 'c';
} elseif (($perms & 0x1000) == 0x1000) {
// FIFO pipe
$info = 'p';
} else {
// Unknown
$info = 'u';
}
// Owner
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ?
(($perms & 0x0800) ? 's' : 'x' ) :
(($perms & 0x0800) ? 'S' : '-'));
// Group
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ?
(($perms & 0x0400) ? 's' : 'x' ) :
(($perms & 0x0400) ? 'S' : '-'));
// World
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ?
(($perms & 0x0200) ? 't' : 'x' ) :
(($perms & 0x0200) ? 'T' : '-'));
if($file=='..')
continue;
if(is_dir($file))
{
if($file=='.')
{
echo "<tr><td id='php'><span><a href='$file' id='$file' class='file'><img src='icon.png'>up</a></td><td>$moddate</td><td>$modtime</td><td>$convertedsize</td><td>$info</td></span></tr>";
}
else
echo "<tr><td id='php'><span><a href='$file' id='$file' class='file'><img src='icon.png'>$file</a></td><td>$moddate</td><td>$modtime</td><td>$convertedsize</td><td>$info</td></span></tr>";
}
else if(is_file($file))
{
echo "is file";
$extn = substr(strrchr($file,'.'),1);
if($extn =='php')
echo "<tr><td><span><a href='$file' id='$file' class='file'><img src='php.png'>$file</a></td><td>$moddate</td><td>$modtime</td><td>$convertedsize</td><td>$info</td></span></tr>";
else
echo "<tr><td id='gallery'><span><a href='$file' id='$file' class='file'><img src='gallery.png'>$file</a></td><td>$moddate</td><td>$modtime</td><td>$convertedsize</td><td>$info</td></span></tr>";
}
}
closedir($dir);
echo "</table>";
?>
firstget.php
<?php
function formatSizeUnits($bytes)
{
if ($bytes >= 1073741824)
{
$bytes = number_format($bytes / 1073741824, 2) . ' GB';
}
elseif ($bytes >= 1048576)
{
$bytes = number_format($bytes / 1048576, 2) . ' MB';
}
elseif ($bytes >= 1024)
{
$bytes = number_format($bytes / 1024, 2) . ' KB';
}
elseif ($bytes > 1)
{
$bytes = $bytes . ' Bytes';
}
elseif ($bytes == 1)
{
$bytes = $bytes . ' Byte';
}
else
{
$bytes = '0 Bytes';
}
return $bytes;
}
$full_path=".";
$dir = opendir($full_path) or die("Unable to open directory");
echo getcwd();
echo "<table id='list'><tr><th>Name</th><th>Date</th><th>Time</th><th>Size</th><th>Permissions</th></tr>";
while($file = readdir($dir))
{
//$cwd = getcwd();
date_default_timezone_set('Asia/Kolkata');
$moddate=date("d/m/Y",filemtime($file));
$modtime=date("h:i A",filemtime($file));
$size=filesize($file);
$convertedsize = formatSizeUnits($size);
$perms = fileperms($file);
if (($perms & 0xC000) == 0xC000) {
// Socket
$info = 's';
} elseif (($perms & 0xA000) == 0xA000) {
// Symbolic Link
$info = 'l';
} elseif (($perms & 0x8000) == 0x8000) {
// Regular
$info = '-';
} elseif (($perms & 0x6000) == 0x6000) {
// Block special
$info = 'b';
} elseif (($perms & 0x4000) == 0x4000) {
// Directory
$info = 'd';
} elseif (($perms & 0x2000) == 0x2000) {
// Character special
$info = 'c';
} elseif (($perms & 0x1000) == 0x1000) {
// FIFO pipe
$info = 'p';
} else {
// Unknown
$info = 'u';
}
// Owner
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ?
(($perms & 0x0800) ? 's' : 'x' ) :
(($perms & 0x0800) ? 'S' : '-'));
// Group
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ?
(($perms & 0x0400) ? 's' : 'x' ) :
(($perms & 0x0400) ? 'S' : '-'));
// World
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ?
(($perms & 0x0200) ? 't' : 'x' ) :
(($perms & 0x0200) ? 'T' : '-'));
if($file=='.' || $file=='..')
continue;
if(is_dir($file))
{
echo "<tr><td id='php'><span><a href='$file' id='$file' class='file'><img src='icon.png'>$file</a></td><td>$moddate</td><td>$modtime</td><td>$convertedsize</td><td>$info</td></span></tr>";
}
else if(is_file($file))
{
$extn = substr(strrchr($file,'.'),1);
if($extn =='php')
echo "<tr><td><span><a href='$file' id='$file' class='file'><img src='php.png'>$file</a></td><td>$moddate</td><td>$modtime</td><td>$convertedsize</td><td>$info</td></span></tr>";
else
echo "<tr><td id='gallery'><span><a href='$file' id='$file' class='file'><img src='gallery.png'>$file</a></td><td>$moddate</td><td>$modtime</td><td>$convertedsize</td><td>$info</td></span></tr>";
}
}
closedir($dir);
echo "</table>";
?>
View more threads in the same category:
-
-
Administrator
Do you have a demo URL? It will be easier to detect the problem. Thanks
-
-
This is an itemized instructional exercise on back-end web advancement in PHP. Things like, setting up your server, making the open HTML Pages, I additionally have my NodeJS/Express with MongoDB form directly here. Likewise, excuse me for utilizing pictures to show the codes as opposed to Now that you have the record.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks