Jump to content

how to 'unlink' file from a certain dir.


newrehmi

Recommended Posts

source: http://nl.php.net/manual/en/function.unlink.php

<?php
$fh = fopen('test.html', 'a');
fwrite($fh, '<h1>Hello world!</h1>');
fclose($fh);

mkdir('testdir', 0777);

unlink('test.html');
unlink('testdir');
?> 

 

YAAAAAWN... less than 5 mins of googling/copying/pasting......

 

thanks Mr fast. But i dont understand those script. I want to delete (or unlink file) from another directory (other than same directory)... But, thats not like what I want.... hmm

Link to comment
Share on other sites

Change "testdir" with your directory, obviously. Set a variable to the directory you want and place it in as testdir if the directory is going to be changing.

 

ahhh I already got I, anyway, thanks for the answer.

 

This is what I want.

unlink('dir/dir/dir/file.ext')

 

Link to comment
Share on other sites

Just specify the full or relative path to the file.

 

<?php
// assume this script is in: c:\myproj\myscrypt.php
// we want to delete: c:\myproj\mydata\junkfile.dat

unlink( 'mydata/junkfile.dat' ); // relative
unlink( 'c:/myproj/mydata/junkfile.dat' ); // absolute

// I prefer to provide absolute paths based on a path I'm certain about
unlink( dirname( __FILE__ ) . '/mydata/junkfile.dat' );
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.