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. Link to comment https://forums.phpfreaks.com/topic/193492-how-to-unlink-file-from-a-certain-dir/ 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...... Link to comment https://forums.phpfreaks.com/topic/193492-how-to-unlink-file-from-a-certain-dir/#findComment-1018631 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 Link to comment https://forums.phpfreaks.com/topic/193492-how-to-unlink-file-from-a-certain-dir/#findComment-1018636 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. Link to comment https://forums.phpfreaks.com/topic/193492-how-to-unlink-file-from-a-certain-dir/#findComment-1018639 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') Link to comment https://forums.phpfreaks.com/topic/193492-how-to-unlink-file-from-a-certain-dir/#findComment-1018642 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' ); ?> Link to comment https://forums.phpfreaks.com/topic/193492-how-to-unlink-file-from-a-certain-dir/#findComment-1018643 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.. Link to comment https://forums.phpfreaks.com/topic/193492-how-to-unlink-file-from-a-certain-dir/#findComment-1018652 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.