ejazshah Posted September 21, 2009 Share Posted September 21, 2009 Hi All, I have setup an apache server on XP with simple functionalities like upload, download and delete. I am done with upload and download part. I dont know how to delete files. I know about unlink. But I have failed to implement it in my situation. In my situation, all files are displayed in directory called uploads, the path is as under: http://localhost:8085/test/Upload/uploaddocs/ (when this is entered in browser you can view all files uploaded). If I need to delete any selected file, How to go about it? I have spent 3 days working on it. I know about unlink but I have failed to figure it out how to use it in my situation.KIndly help me. Ejaz Quote Link to comment https://forums.phpfreaks.com/topic/175034-problem-in-deleting-files-from-server-once-uploaded/ Share on other sites More sharing options...
mikesta707 Posted September 21, 2009 Share Posted September 21, 2009 to delete a file, just do something like this <?php $file = "test.txt"; if (!unlink($file)) { echo ("Error deleting $file"); } else { echo ("Deleted $file"); } ?> that is assuming that the file test.txt is in the same directory as the script running. if its not you have to use the absolute or relative path to the file. what does your code look like now Quote Link to comment https://forums.phpfreaks.com/topic/175034-problem-in-deleting-files-from-server-once-uploaded/#findComment-922474 Share on other sites More sharing options...
ejazshah Posted September 21, 2009 Author Share Posted September 21, 2009 the code is exactly the same as you have mentioned. But there are 2 problems: 1) I want the file name to be selected by the user accessing my server. So i cant specify the file name. It should be passed as a paramter on click or if there is any other suitable way (and I dont know how to do that). 2) This piece of code is working fine but only for the file name specified. there are many files listed on the server. If some user want to delete one file he wont be having access to the unlink code to specify the filename. I want it to work as if as a user you click on a file to delete, it pops up a message asking Are you sure you want to delete file? and on pressing ok it should remove it from the server Need you help.. Quote Link to comment https://forums.phpfreaks.com/topic/175034-problem-in-deleting-files-from-server-once-uploaded/#findComment-922480 Share on other sites More sharing options...
mikesta707 Posted September 21, 2009 Share Posted September 21, 2009 pass the filename as a post variable? if necessary pass the folder path relative to the script itself also, but you only really need to do that if the the files that want to be deleted exist in different directories. The confirmation popup can be done with javascript. Quote Link to comment https://forums.phpfreaks.com/topic/175034-problem-in-deleting-files-from-server-once-uploaded/#findComment-922483 Share on other sites More sharing options...
ejazshah Posted September 21, 2009 Author Share Posted September 21, 2009 I am done with the confirmation popup. But I dont know how to pass filename through post. The files are displayed as follow as href (automatically generated as a result of upload) Index of /test/Upload/uploaddocs Parent Directory Installation Guide for Apache 2.2.13.docx Installation_Guide_for_Apache_2.2.13.pdf MIC_Pilot1000_Requirement_Specification.doc MobidiaMeasurementTool Test Plan Result.xls Olympic memo AEP.pdf del.php delete.php delete1.php delete2.php delete3.php flowplayer-3.1.3/ pic.jpg sample.xlsx Now I want that if some one clicks on any file, its should pop up a message and then delete it? Kindly give some guidance on how to pass the file name since the source code of this page is automatically generated (which cant be modified)which can be viiewed as right click View Source: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <html> <head> <title>Index of /test/Upload/uploaddocs</title> </head> <body> <h1>Index of /test/Upload/uploaddocs</h1> <ul><li><a href="/test/Upload/"> Parent Directory</a></li> <li><a href="Installation%20Guide%20for%20Apache%202.2.13.docx"> Installation Guide for Apache 2.2.13.docx</a></li> <li><a href="Installation_Guide_for_Apache_2.2.13.pdf"> Installation_Guide_for_Apache_2.2.13.pdf</a></li> <li><a href="MAG%20Installation,%20Reference,%20and%20Miscellaneous%20Linux%20Commands(build).doc"> MAG Installation, Reference, and Miscellaneous Linux Commands(build).doc</a></li> <li><a href="MAG%20Team%20Code%20Review%20Process.doc"> MAG Team Code Review Process.doc</a></li> <li><a href="Olympic%20memo%20AEP.pdf"> Olympic memo AEP.pdf</a></li> <li><a href="del.php"> del.php</a></li> <li><a href="delete.php"> delete.php</a></li> <li><a href="delete1.php"> delete1.php</a></li> <li><a href="delete2.php"> delete2.php</a></li> <li><a href="delete3.php"> delete3.php</a></li> <li><a href="flowplayer-3.1.3/"> flowplayer-3.1.3/</a></li> <li><a href="pic.jpg"> pic.jpg</a></li> <li><a href="sample.xlsx"> sample.xlsx</a></li> </ul> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/175034-problem-in-deleting-files-from-server-once-uploaded/#findComment-922493 Share on other sites More sharing options...
mikesta707 Posted September 21, 2009 Share Posted September 21, 2009 Why can't you modify the source? You could make the links go to the delete page (obviously, have an onclick attribute for your popup) and pass the filename as a get variable. for example, a link may look like this <a href="delete.php?page=Installation_Guide_for_Apache_2.2.13.pdf">Installation_Guide_for_Apache_2.2.13.pdf</a> Quote Link to comment https://forums.phpfreaks.com/topic/175034-problem-in-deleting-files-from-server-once-uploaded/#findComment-922496 Share on other sites More sharing options...
ejazshah Posted September 21, 2009 Author Share Posted September 21, 2009 My upload.html code is: <html> <body> <form enctype="multipart/form-data" action="upload_file.php" method="POST"> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> <a href="uploaddocs/"><h1>Documents</h1></a> </form> </body> </html> upload_file.php and the print screen of once file is uploaded(the page showing directory in which files are uploaded) are attached with the mail. Kindly tell me how to get that href link in there with every file that is uploaded? Kindly help me. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/175034-problem-in-deleting-files-from-server-once-uploaded/#findComment-922507 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.