Jump to content


Photo

Small Question?


  • Please log in to reply
4 replies to this topic

#1 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 24 September 2006 - 12:08 PM

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

#2 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 24 September 2006 - 12:15 PM

Yup

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

#3 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 24 September 2006 - 12:17 PM

Would I be able to drop any other queries i have after checking these through php.net?

#4 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 24 September 2006 - 12:52 PM

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:

<?php

$filename = "myfile.txt";

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

?>


#5 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 24 September 2006 - 06:29 PM

You do not have to check if it exists, just mute the error it would return:
@unlink("some_file");





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users