Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use <a href="http://php.net/unlink" rel="noreferrer"><code>unlink</code></a> to remove a file, and <a href="http://php.net/manual/en/language.constants.predefined.php" rel="noreferrer"><code>__FILE__</code></a> to get the full path to the current file :</p> <pre><code>unlink(__FILE__); </code></pre> <p>As a "proof" :</p> <pre><code>squale@shark:~/developpement/tests/temp $ ll | grep 'remove-myself.php' -rw-r--r-- 1 squale squale 25 2009-08-01 17:01 remove-myself.php </code></pre> <p>=> The file exists</p> <pre><code>squale@shark:~/developpement/tests/temp $ cat remove-myself.php &lt;?php unlink(__FILE__); </code></pre> <p>=> It contains the code I gave</p> <pre><code>squale@shark:~/developpement/tests/temp $ php ./remove-myself.php </code></pre> <p>=> I launch the script</p> <pre><code>squale@shark:~/developpement/tests/temp $ ll | grep 'remove-myself.php' </code></pre> <p>=> It doesn't exist anymore</p> <p><br> For this to work, you'll have to be sure you have the required privilegies... this means the user trying to delete the file needs to have right-access on the directory containing it.</p> <p>When you are in command line, it's generally OK ; but if you are trying to do this via Apache, you will need to give Apache write-access to that directory/file -- Apache doesn't generally have that kind of privilege by default <em>(not secure, and generally not needed)</em></p> <p><br> <em>Not sure it'd be possible on windows, though... It works on Linux, but Windows might kinda "lock" the file when it's being executed...</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload