fuzzy29 Posted January 10, 2009 Share Posted January 10, 2009 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 More sharing options...
nuttycoder Posted January 10, 2009 Share Posted January 10, 2009 to delete file from a server use UNLINK() as unlinking a file actually removes the file from the server note this won't work on a windows server I don't think. unlink ($filename); Link to comment https://forums.phpfreaks.com/topic/140271-php-file-manager/#findComment-733972 Share on other sites More sharing options...
pyrox Posted January 10, 2009 Share Posted January 10, 2009 Im pretty sure that if you are running apache the unlink command will still work but dont quote me on that Link to comment https://forums.phpfreaks.com/topic/140271-php-file-manager/#findComment-733974 Share on other sites More sharing options...
nuttycoder Posted January 10, 2009 Share Posted January 10, 2009 could be I never used a windows server so I don't know. Link to comment https://forums.phpfreaks.com/topic/140271-php-file-manager/#findComment-733977 Share on other sites More sharing options...
fuzzy29 Posted January 10, 2009 Author Share Posted January 10, 2009 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 More sharing options...
nuttycoder Posted January 10, 2009 Share Posted January 10, 2009 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 More sharing options...
fuzzy29 Posted January 10, 2009 Author Share Posted January 10, 2009 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 More sharing options...
nuttycoder Posted January 10, 2009 Share Posted January 10, 2009 have you got a page listing all the files uploaded? Link to comment https://forums.phpfreaks.com/topic/140271-php-file-manager/#findComment-734023 Share on other sites More sharing options...
fuzzy29 Posted January 10, 2009 Author Share Posted January 10, 2009 have you got a page listing all the files uploaded? Yes, i'll post a link in a minute Link to comment https://forums.phpfreaks.com/topic/140271-php-file-manager/#findComment-734058 Share on other sites More sharing options...
fuzzy29 Posted January 10, 2009 Author Share Posted January 10, 2009 have you got a page listing all the files uploaded? Yes, i'll post a link in a minute http://www.fuzzy29.comze.com user:phpfreak pass:password Link to comment https://forums.phpfreaks.com/topic/140271-php-file-manager/#findComment-734062 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.