Results 1 to 4 of 4

Thread: Php Action unlink function

  1. #1
    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:
    <? 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?

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    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.

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    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.

  4. #4
    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

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



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

    123456

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

Similar Threads

  1. c++ equivalent function to the c-function 'sprintf
    By Dilbert in forum Software Development
    Replies: 6
    Last Post: 13-12-2011, 04:03 PM
  2. c# function equivalent to gettime function in javascript
    By Omaar in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 10:44 PM
  3. Replies: 5
    Last Post: 27-02-2010, 07:52 PM
  4. How does abstract function differs from virtual function?
    By Maddox G in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 11:32 AM
  5. Function keys don't function under windows XP
    By GunFighter in forum Hardware Peripherals
    Replies: 3
    Last Post: 08-04-2009, 11:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,657,346.91154 seconds with 16 queries