Jump to content

Archived

This topic is now archived and is closed to further replies.

xyn

Small Question?

Recommended Posts

Hey Guys,
I've got this small idea but i think it's not going to work, but
is there a way of using [b]PHP[/b] to [b]DELETE[/b] a [b]FILE[/b]
from a directory?

Share this post


Link to post
Share on other sites
Yup

Check out unlink() you'll also want file_exists() too to make sure the file is there before you delete (unlink) it.

Share this post


Link to post
Share on other sites
Would I be able to drop any other queries i have after checking these through php.net?

Share this post


Link to post
Share on other sites
How do you mean?  If you have have any other questions about things?  Just ask :) 

In regards to the unlink() it would work like this:

[code]
<?php

$filename = "myfile.txt";

if(file_exists($filename)) {
  unlink($filename);
} else {
  echo "I cannot find the file to delete.";
}

?>
[/code]

Share this post


Link to post
Share on other sites
You do not have to check if it exists, just mute the error it would return: [code]@unlink("some_file");[/code]

Share this post


Link to post
Share on other sites

×

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.