•
•
•
•
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
![]() |
•
•
Join Date: Jul 2007
Posts: 16
Reputation:
Rep Power: 2
Solved Threads: 0
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
jpgview.php. From this file del.php will be called
My problem is I am unable to get the buttons corresponding image name and send it to del.php
Thanx in advance
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
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
Try this.
This lists all the images in the specified folder.
This code deletes that image and sends the user back to the image listing page.
This works.
Cheers,
Naveen
This lists all the images in the specified folder.
php Syntax (Toggle Plain Text)
<?php $jpgdir = "./uploads/jpg/"; $dh = opendir($jpgdir); echo "JPG FILES"; print("<table border=2>"); while (($file = readdir($dh)) !== false) { if($file!='.' && $file!='..') { print( "<tr><td>"); print("<form name=del method=post action=\"del.php\">"); echo "<A HREF=\"$jpgdir/$file\"><IMG src=\"$jpgdir/$file\"/ height=70 width=70></A><BR>\n"; echo "<input type=\"hidden\" name=\"path\" value=\"$jpgdir/$file\">"; print("</td><td>"); echo "<input type=\"submit\" name=\"del\" value=\"Delete\">"; print("</td></tr>"); print("</form>"); } } print("</table>"); closedir($dh); ?>
php Syntax (Toggle Plain Text)
<?php $jpgdir = "./uploads/jpg/";; $file=$_REQUEST['path']; // Open a known directory, and proceed to read its contents if (is_dir($jpgdir)) { if ($dh = opendir($jpgdir)) { unlink($file); closedir($dh); } } header("location: jpgview.php"); ?>
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*
*PM asking for help will be ignored*
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
advertising architecture backup blog breach business centro competition crash daniweb data protection database design development enterprise files fix flash flv government hacker hyper-v internet linux mail media microsoft mmorpg news normalization open php qmail red hat rhel security server smtp software source spam sql ssvichosst streaming survey video virus web windows windows server
- Spyfalcon & Malwarewipe, and I can't get ride of it! (Viruses, Spyware and other Nasties)
- Virus ALert! (Viruses, Spyware and other Nasties)
- guidence urgently needed! (IT Careers and Business)
Other Threads in the PHP Forum
- Previous Thread: $_FILES help
- Next Thread: fopen fwrite in php4



Linear Mode