Help on Deleting files from server- no database

Thread Solved

Join Date: Jul 2007
Posts: 29
Reputation: creativehacker is an unknown quantity at this point 
Solved Threads: 0
creativehacker creativehacker is offline Offline
Light Poster

Help on Deleting files from server- no database

 
0
  #1
Feb 2nd, 2008
Hi everyone, I want to delete uploaded files from the server. here I am not using database please check my code and suggest me any changes

Del.php

  1. <?php
  2. $jpgdir = "uploads/";
  3. $file=$_REQUEST['file1'];
  4. echo $file;
  5.  
  6. //echo $jpgdir;
  7. // Open a known directory, and proceed to read its contents
  8. if (is_dir($jpgdir)) {
  9. if ($dh = opendir($jpgdir)) {
  10. unlink($jpgdir . "/" . $file);
  11. closedir($dh);
  12. }
  13. }
  14. ?>


jpgview.php. From this file del.php will be called

  1. <?php
  2. $jpgdir = "uploads/jpg";
  3.  
  4. $dh = opendir($jpgdir);
  5. echo "JPG FILES";
  6.  
  7. print("<form name=del action=\"del.php\">");
  8. print("<table border=2>");
  9. while (($file = readdir($dh)) !== false) {
  10. if($file!='.' && $file!='..')
  11. {
  12. print( "<tr><td>");
  13. echo "<A HREF=\"$jpgdir/$file\"><IMG src=\"$jpgdir/$file\"/ height=70 width=70></A><BR>\n";
  14. print("</td><td>");
  15. echo "<input type=\"submit\" name=\"del\" value=\"Delete\" id=\"$file\">";
  16. print("</td></tr>");
  17.  
  18. }
  19. }
  20. print("</table>");
  21. print("</form>");
  22. closedir($dh);
  23. ?>

My problem is I am unable to get the buttons corresponding image name and send it to del.php


Thanx in advance
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Help on Deleting files from server- no database

 
0
  #2
Feb 2nd, 2008
Try this.

This lists all the images in the specified folder.
  1. <?php
  2. $jpgdir = "./uploads/jpg/";
  3.  
  4. $dh = opendir($jpgdir);
  5. echo "JPG FILES";
  6.  
  7. print("<table border=2>");
  8. while (($file = readdir($dh)) !== false) {
  9. if($file!='.' && $file!='..')
  10. {
  11. print( "<tr><td>");
  12. print("<form name=del method=post action=\"del.php\">");
  13. echo "<A HREF=\"$jpgdir/$file\"><IMG src=\"$jpgdir/$file\"/ height=70 width=70></A><BR>\n";
  14. echo "<input type=\"hidden\" name=\"path\" value=\"$jpgdir/$file\">";
  15. print("</td><td>");
  16. echo "<input type=\"submit\" name=\"del\" value=\"Delete\">";
  17. print("</td></tr>");
  18. print("</form>");
  19. }
  20. }
  21. print("</table>");
  22. closedir($dh);
  23. ?>
This code deletes that image and sends the user back to the image listing page.
  1. <?php
  2. $jpgdir = "./uploads/jpg/";;
  3. $file=$_REQUEST['path'];
  4.  
  5. // Open a known directory, and proceed to read its contents
  6. if (is_dir($jpgdir)) {
  7. if ($dh = opendir($jpgdir)) {
  8. unlink($file);
  9. closedir($dh);
  10. }
  11. }
  12. header("location: jpgview.php");
  13. ?>

This works.

Cheers,
Naveen
Last edited by nav33n; Feb 2nd, 2008 at 7:52 am.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 29
Reputation: creativehacker is an unknown quantity at this point 
Solved Threads: 0
creativehacker creativehacker is offline Offline
Light Poster

Re: Help on Deleting files from server- no database

 
0
  #3
Feb 2nd, 2008
Thank you very much
It worked ..
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Help on Deleting files from server- no database

 
0
  #4
Feb 2nd, 2008
you are welcome
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC