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?
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.
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.
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:
How do you then work to make sure the file exists and how to remove them you will still have other questions.