Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Php Action unlink function

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 13-03-2009
Member
 
Join Date: Jan 2009
Posts: 38
Php Action unlink function
  

Yesterday I made a website for my project, which by means of a list of all php files in a folder is generated. Now I want it on a certain page (the administration) is possible for files to remove the server so that other users no longer will see. The list where the users file list is created that is independent of management, so users will not have these options.

Anyway, back to the file management. I would prefer that the management is possible by means of clicking a small image (of a cross, etc., but iig an image) the files to delete. Well I know you with php unlink a file can delete, but my question is how I unlink function that plate coupling. I tried with onclick, but I was not (though the chance is very great that I have done something wrong). Who can explain to me how it should?

The code that generates the list is sufficient:


Code:
Quote:
<? php
if ($ handle = opendir ( "uploads /")) (
while (false! == ($ file = readdir ($ handle)))
(
if ($ file! = "." & & $ file! = "..")
(
$ thelist .= '<a href="uploads/'.$file.'" target="_blank">. $ file. "</ a>';
)
)
closedir ($ handle);
)
>

<P> Below is the list of files: </ p>
<P> <? = $ Thelist> </ p>

It must be behind that </ a> too. Has anyone an idea?

Reply With Quote
  #2  
Old 13-03-2009
Member
 
Join Date: Feb 2008
Posts: 1,845
Re: Php Action unlink function

a <a> around a <img> locations, and in that link you call for example delete.php? = file, and then you just put $ file.
And in delete.php do you first check whether the file exists, and whether the file is (otherwise you can just delete everything from your server), and whether the user has rights to that file correctly.
If so, then unlink () apply.
Reply With Quote
  #3  
Old 13-03-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: Php Action unlink function

If the link to delete.php? File = 123456 link. Then would it be to you in a database file with the ID 123456. You look what file it is and you removed the file and the corresponding record from the database.

Of course you may disconnect some controls in order to see if the user calls delete.php the rights to that specific file to delete.

Your ID can be replaced by the file if necessary. But I would surely think very carefully about the security of this action.
Reply With Quote
  #4  
Old 13-03-2009
Member
 
Join Date: Dec 2008
Posts: 207
Re: Php Action unlink function

I am not a PHP hero, but what you have got the script is only displaying the list of files in the upload folder.

How do you delete a file I do not know, but I would deal with one type of form or an action link when you are on a link (which may be an image).

The link would include as Civil mentions delete.php? File = 123456.
You have a "delete.php" file that performs the above checks (there is a file and you have rights to delete etc.).

The link (a href = "delete.php? File = 123456") so to (leave) to call a value from the "file" table in your database (if you use it), this can read with a $ _GET [ 'file'] in delete.php.

Delete.php

Quote:
Code: 1 $ filename = $ _GET [ 'file'];



With an echo / print of '$ filename' will result in the following text:

Quote:
123456

How do you then work to make sure the file exists and how to remove them you will still have other questions.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Php Action unlink function"
Thread Thread Starter Forum Replies Last Post
c++ equivalent function to the c-function 'sprintf Dilbert Software Development 6 13-12-2011 04:03 PM
c# function equivalent to gettime function in javascript Omaar Software Development 4 10-03-2010 10:44 PM
How to pass function with parameters to another function in PHP? Linoo Software Development 5 27-02-2010 07:52 PM
How does abstract function differs from virtual function? Maddox G Software Development 5 29-01-2010 11:32 AM
Function keys don't function under windows XP GunFighter Hardware Peripherals 3 09-04-2009 12:07 AM


All times are GMT +5.5. The time now is 06:58 AM.