newrehmi Posted February 26, 2010 Share Posted February 26, 2010 I want to delete a file from a certain directory, not in the same directory. May someone write the script here... Thanks for the answers. Quote Link to comment Share on other sites More sharing options...
jskywalker Posted February 26, 2010 Share Posted February 26, 2010 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...... Quote Link to comment Share on other sites More sharing options...
newrehmi Posted February 26, 2010 Author Share Posted February 26, 2010 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 Quote Link to comment Share on other sites More sharing options...
aebstract Posted February 26, 2010 Share Posted February 26, 2010 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. Quote Link to comment Share on other sites More sharing options...
newrehmi Posted February 26, 2010 Author Share Posted February 26, 2010 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') Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 26, 2010 Share Posted February 26, 2010 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' ); ?> Quote Link to comment Share on other sites More sharing options...
jskywalker Posted February 26, 2010 Share Posted February 26, 2010 source: http://nl.php.net/manual/en/function.unlink.php But, thats not like what I want.... hmm on this php.net pages you always do have to take a look at the user comments.... they mostly make thing clearer... But luckily the solution is already pointed out.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.