steviez Posted April 2, 2007 Share Posted April 2, 2007 Hi, I am running a file hosting site, when a user uploads a file they are given a download link upon successfull upload. Is it possable to also give them a delete link? If so how?? The download link is in this form: <?php echo SITE_URL."/v/".$_SESSION['key']."/".$rsFile->fields['filename'].".html"; ?> Quote Link to comment Share on other sites More sharing options...
emehrkay Posted April 2, 2007 Share Posted April 2, 2007 just an idea - store a reference to the file in a table. in that table store a unique-random val and use it as a part of the url. delete.php?id=asdlaksjdfasodfjals2323 then just run a check against that id Quote Link to comment Share on other sites More sharing options...
jitesh Posted April 2, 2007 Share Posted April 2, 2007 yes its easy. generate a file delete.php file and use unlink(); Quote Link to comment Share on other sites More sharing options...
steviez Posted April 2, 2007 Author Share Posted April 2, 2007 im new to php, anyone help at all? Quote Link to comment Share on other sites More sharing options...
emehrkay Posted April 2, 2007 Share Posted April 2, 2007 what i am saying assumes that you store a referece to each file uploaded in a db table. in that table add a field that id's the file, some random 15 char string on your delete link do delete.php?file=randomstringasdfasodf in your delete.php file do $file = $_GET['file']; then check the db for that random unique string 'SELECT path FROM files WHERE identifer = '. $file; now you have the path to that file that you stored in that same table unlink(that file path); Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 2, 2007 Share Posted April 2, 2007 Maybe the freelance section or book review might help, as we can help you but we're not going to write the whole thing for you. Quote Link to comment Share on other sites More sharing options...
steviez Posted April 2, 2007 Author Share Posted April 2, 2007 Hi, Thanks for all your help so far, I have managed to get a delet code generated and working, also i can get the code to delet the file from the DB. The only thing i can not do is remove it from the server... here is my file: <?php include "admin/config.php"; include "conn.php"; include "functions.php"; $file = $_GET['file']; $strSql = "select * from xl_files WHERE del_key = $file"; $rsFile = $conn->execute($strSql); if(file_exists($file)){ unlink($rsFile); } $strSql = "delete from xl_files WHERE del_key = $file"; $conn->execute($strSql); goto("index.php".strstr($_SERVER['HTTP_REFERER'],"?")); ?> any ideas whats wrong? Quote Link to comment Share on other sites More sharing options...
emehrkay Posted April 2, 2007 Share Posted April 2, 2007 is $file a random code or a path to the file? if(file_exists($file)){ unlink($rsFile); } Quote Link to comment Share on other sites More sharing options...
steviez Posted April 2, 2007 Author Share Posted April 2, 2007 random code Quote Link to comment Share on other sites More sharing options...
emehrkay Posted April 2, 2007 Share Posted April 2, 2007 i would assume that $rsFile is the path to the file? if so, you need to check to see if that exists, not your random code Quote Link to comment Share on other sites More sharing options...
steviez Posted April 2, 2007 Author Share Posted April 2, 2007 i did not write the script, im thinking that the $rsFile is part of the mysql code as it is in all of the script Quote Link to comment Share on other sites More sharing options...
steviez Posted April 3, 2007 Author Share Posted April 3, 2007 Any ideas guys? Quote Link to comment 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.