User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 428,634 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,968 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 644 | Replies: 3 | Solved
Reply
Join Date: Jul 2007
Posts: 16
Reputation: creativehacker is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
creativehacker creativehacker is offline Offline
Newbie Poster

Question Help on Deleting files from server- no database

  #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

<?php
$jpgdir = "uploads/";
$file=$_REQUEST['file1'];
echo $file;

//echo $jpgdir;
// Open a known directory, and proceed to read its contents
if (is_dir($jpgdir)) {
   if ($dh = opendir($jpgdir)) {
              unlink($jpgdir . "/" . $file);
       closedir($dh);
   }
}
?>


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

<?php
$jpgdir = "uploads/jpg";

$dh = opendir($jpgdir);
echo "JPG FILES";

print("<form name=del action=\"del.php\">");
print("<table border=2>");
while (($file = readdir($dh)) !== false) {
	if($file!='.' && $file!='..')
	{
	print( "<tr><td>");
echo "<A HREF=\"$jpgdir/$file\"><IMG src=\"$jpgdir/$file\"/ height=70 width=70></A><BR>\n";
	print("</td><td>");
		echo "<input type=\"submit\" name=\"del\" value=\"Delete\" id=\"$file\">";
print("</td></tr>");

	}
}
print("</table>");
print("</form>");
closedir($dh);
?>

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


Thanx in advance
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Help on Deleting files from server- no database

  #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 6:52 am.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Jul 2007
Posts: 16
Reputation: creativehacker is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
creativehacker creativehacker is offline Offline
Newbie Poster

Re: Help on Deleting files from server- no database

  #3  
Feb 2nd, 2008
Thank you very much
It worked ..
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Help on Deleting files from server- no database

  #4  
Feb 2nd, 2008
you are welcome
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 12:52 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC