Congratulations to AcaCandy on her 100,000th post!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen boot bsod computer connection crash css dell driver drivers email error ethernet excel explorer firefox firefox 3 game hard drive internet internet explorer itunes laptop linux malware monitor network networking nvidia outlook outlook 2003 outlook 2007 outlook express partition problem router slow software sound trojan usb video virus vista windows windows vista windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Solved: PHP Unlink() Help


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
Xperience's Avatar
Computer Specs
Senior Member with 136 posts.
 
Join Date: Feb 2007
Location: Australia
Experience: Microsoft Desktop Support Technician
28-Feb-2007, 04:00 AM #1
Solved: PHP Unlink() Help
Hi

What i need is some functionality for me and my other admins to delete files on our server.
The page has been setup to display the files on the server, but now we just need as of above.

So next to each file name, maybe a checkbox and then admins check the boxes in relation to the files they want to delete. Then they click a submit button and the files are deleted.

Let your mind go wild. I am willing to complete any procedure you supply me
Xperience's Avatar
Computer Specs
Senior Member with 136 posts.
 
Join Date: Feb 2007
Location: Australia
Experience: Microsoft Desktop Support Technician
01-Mar-2007, 04:45 PM #2
Bump
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
01-Mar-2007, 05:03 PM #3
You can use glob() to create a list of files. In your form, you can name each checkbox something like "FilesList[]". PHP will get an array of the files you selected, and you can use a foreach() loop to delete each one.
Xperience's Avatar
Computer Specs
Senior Member with 136 posts.
 
Join Date: Feb 2007
Location: Australia
Experience: Microsoft Desktop Support Technician
01-Mar-2007, 05:32 PM #4
Hi

Umm i really dont understand sorry lol I already have the list of files created. What do i put for form action? And if its a something.php file, what goes in that file?

Thanks
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
01-Mar-2007, 08:57 PM #5
Your forms action is where you want the results to go. You might want to take a look at the manual at php.net if you don't know how to write any of it.
Xperience's Avatar
Computer Specs
Senior Member with 136 posts.
 
Join Date: Feb 2007
Location: Australia
Experience: Microsoft Desktop Support Technician
02-Mar-2007, 01:44 AM #6
okay, but how do i delete the files? what code do i need? could you possibly supply a sample code and then i may be able to go from there?
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,248 posts.
 
Join Date: Oct 2006
02-Mar-2007, 06:13 AM #7
Do you know how to make a checkbox or radio button form?
Xperience's Avatar
Computer Specs
Senior Member with 136 posts.
 
Join Date: Feb 2007
Location: Australia
Experience: Microsoft Desktop Support Technician
02-Mar-2007, 04:31 PM #8
I certainly do. I just need php code
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
02-Mar-2007, 06:18 PM #9
To delete a file, you do unlink('filename');. If you could post what code you have or what you're stuck on, it might be easier to help.
Xperience's Avatar
Computer Specs
Senior Member with 136 posts.
 
Join Date: Feb 2007
Location: Australia
Experience: Microsoft Desktop Support Technician
02-Mar-2007, 10:20 PM #10
Okay, im stuck on how i can select multiple files for deletion, and then click a button and they delete.
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
02-Mar-2007, 10:44 PM #11
Take a look at post #3. If you name your checkboxes like FilesToDelete[], it will pass an array of the files you select. Then you can run unlink() on each one to delete it.
Xperience's Avatar
Computer Specs
Senior Member with 136 posts.
 
Join Date: Feb 2007
Location: Australia
Experience: Microsoft Desktop Support Technician
03-Mar-2007, 12:00 AM #12
awesome! so then the unlink code will go in delete.php for example and form action will be "delete.php"? If so, great! And then what do i use for filename in unlink() function? (i.e the name between the brackets).

And with the FilesToDelete[], in between the braces, do i put a number? For example:

HTML Code:
<input type='checkbox' name='FilesToDelete[1]'>
Or do i name each checkbox just FilesToDelete[] with no number in the braces?
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
03-Mar-2007, 12:02 AM #13
That's correct. You need to use a loop to delete each file:
PHP Code:
foreach($_POST['FileToDelete'] as $filename)
{
  
unlink($filename);

Xperience's Avatar
Computer Specs
Senior Member with 136 posts.
 
Join Date: Feb 2007
Location: Australia
Experience: Microsoft Desktop Support Technician
03-Mar-2007, 12:13 AM #14
cool. so that code will go in delete.php? And then i dont put numbers in the braces?
Xperience's Avatar
Computer Specs
Senior Member with 136 posts.
 
Join Date: Feb 2007
Location: Australia
Experience: Microsoft Desktop Support Technician
03-Mar-2007, 12:32 AM #15
Alrighty Seems to be going fine except:

Warning: unlink(/www/110mb.com/t/o/m/m/o/8/8/8/tommo888/htdocs/on) [function.unlink]: No such file or directory in /www/110mb.com/t/o/m/m/o/8/8/8/tommo888/htdocs/admin/delete.php on line 5

Why "on" instead of the file i want to delete?
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 06:42 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.