0

I need a code that deletes every file in a special folder with special name but every suffix.

For example:

sample.txt
sample.jpg
sample.pdf
sample.png

I work with Zend Framework. Has zend any tools for deleting files?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
afsane
  • 1,889
  • 6
  • 25
  • 40

2 Answers2

3

look on unlink function

<?php
   $mask = "sample.*"
   array_map( "unlink", glob( $mask ) );
?>
Haim Evgi
  • 123,187
  • 45
  • 217
  • 223
  • +1 for a very concise way of doing it. I'm commenting to say that OP should read the docs for array_map() and glob() carefully. Also: OP probably wants to pass something to chdir() unless his images are in the same directory as his script. – timdev May 02 '11 at 06:06
1

There is a Zend_File class in Zend Framework. But as you may read in the documentation it provides functionality for transferring and validating files.

Since Zend Framework is written in PHP you can use default delete() or unlink() method, e.g.

$filename = "myfile.txt";
unlink($filename);
BenMorel
  • 34,448
  • 50
  • 182
  • 322
DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601