Jump to content

PHP File manager


fuzzy29

Recommended Posts

I have a server with a PHP authenticated log on script. I'm a noob to PHP but know a lot of HTML. I want to make a file manager so that I can delete files on my server. The

 

$myFile = "FILE I WANT TO DELETE"; $fh = fopen($myFile, 'w') or die("can't open file"); fclose($fh); 

 

script is OK, but I want a way so that when I upload a file, there is a button next to it that I can click and it will delete it. Does anyone know how to do this or any tutorial sites?

Thanks, Dan

 

Link to comment
https://forums.phpfreaks.com/topic/140271-php-file-manager/
Share on other sites

It's running on a linux server. The thing I want it to do is automatically create the unlink file for every file I upload. I understand that the process must be something like:

 

Check for files  -->  create unlink file for that name  -->  alert user that the file for deleting this is called www.myserver.com/delete(FILENAME

 

That's what I was sortta hoping for.

Link to comment
https://forums.phpfreaks.com/topic/140271-php-file-manager/#findComment-733988
Share on other sites

okay assuming all uploaded files have a refernece in a database:

 

list all files:

 

<?php
$result = mysql_query("SELECT * FROM files")or die(mysql_error());
$Rows = mysql_num_rows($result);
?>
<table>
<tr>
<td><strong>Gallery</strong></td>
<td><strong>Action</strong></td>
</tr>
<?php
while ($row = mysql_fetch_object($result)) {
?>
<tr>
<td><?php echo $row->fileTitle;?></td>
<td><a href="javascript:delfile('<?php echo $row->fileID;?>','<?php echo $row->fileTitle;?>');">Delete</a></td>
</tr>
<?php
}
?>
</table>

 

The delete link called javascript to confirm delete put this in the header:

 

<script type="text/javascript">
function delfile(fileID, fileTitle)
{
   if (confirm("Are you sure you want to delete '" + fileTitle + "'"))
   {
      window.location.href = 'index.php?delfile=' + fileID;
   }
}
</script>

 

then if yes is confirmed these php will be run:

 

<?php
if(isset($_GET['delfile']))
{

$query = "SELECT * FROM  files  WHERE fileID = '{$_GET['delfile']}'";
$result = mysql_query($query) or die('problem: ' . mysql_error());

while ( $row = mysql_fetch_array ($result)) {
if($row['fileTitle'] !== ''){
unlink ($row['fileTitle']);
}	
}

  $query = "DELETE FROM files WHERE fileID = '{$_GET['delfile']}'";
  mysql_query($query) or die('Error : ' . mysql_error());

   header('Location: ' . $_SERVER['HTTP_REFERER']);
   exit;
}?>

 

Gets the file from the database checks to see if it exists if it does it then deletes it and reloads the page.

Link to comment
https://forums.phpfreaks.com/topic/140271-php-file-manager/#findComment-733999
Share on other sites

okay assuming all uploaded files have a refernece in a database:

 

list all files:

 

<?php
$result = mysql_query("SELECT * FROM files")or die(mysql_error());
$Rows = mysql_num_rows($result);
?>
<table>
<tr>
<td><strong>Gallery</strong></td>
<td><strong>Action</strong></td>
</tr>
<?php
while ($row = mysql_fetch_object($result)) {
?>
<tr>
<td><?php echo $row->fileTitle;?></td>
<td><a href="javascript:delfile('<?php echo $row->fileID;?>','<?php echo $row->fileTitle;?>');">Delete</a></td>
</tr>
<?php
}
?>
</table>

 

The delete link called javascript to confirm delete put this in the header:

 

<script type="text/javascript">
function delfile(fileID, fileTitle)
{
   if (confirm("Are you sure you want to delete '" + fileTitle + "'"))
   {
      window.location.href = 'index.php?delfile=' + fileID;
   }
}
</script>

 

then if yes is confirmed these php will be run:

 

<?php
if(isset($_GET['delfile']))
{

$query = "SELECT * FROM  files  WHERE fileID = '{$_GET['delfile']}'";
$result = mysql_query($query) or die('problem: ' . mysql_error());

while ( $row = mysql_fetch_array ($result)) {
if($row['fileTitle'] !== ''){
unlink ($row['fileTitle']);
}	
}

  $query = "DELETE FROM files WHERE fileID = '{$_GET['delfile']}'";
  mysql_query($query) or die('Error : ' . mysql_error());

   header('Location: ' . $_SERVER['HTTP_REFERER']);
   exit;
}?>

 

Gets the file from the database checks to see if it exists if it does it then deletes it and reloads the page.

 

I have the files stored in a directory so that you can view them by going to www.example.com/uploaded they're not in a mysql database, is there any wy to adapt the code for that? And thanks for the code it will help on a different project

Link to comment
https://forums.phpfreaks.com/topic/140271-php-file-manager/#findComment-734021
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.