PHP File Operations Summary (delete the specified file/Get folder under the filename/Read folder under the picture name) _php Tips

Source: Internet
Author: User

This article analyzes the method of PHP file operation. Share to everyone for your reference, specific as follows:

Delete a file

Unlink ()

Syntax: int unlink (string filename);

return value: Integer

Function type: file access. Such as:

Unlink ("Tmp/test.txt");

Second, get the file name under the folder

$dir = "message/"; Name of folder
if (Is_dir ($dir)) {
  if ($dh = Opendir ($dir)) {while
    ($file = Readdir ($DH))!== false) {
      echo file Name: $file <br> ";
    }
    Closedir ($DH);
  }


Third, read the name of the picture under the folder

<?php
$handle = opendir (' images/');//current directory while
  (false!== ($file = Readdir ($handle)) {//traverse the directory
   where the PHP file resides List ($filesname, $KZM) =explode (".", $file);//Gets the extension
    if ($kzm = = "gif" or $kzm = = "jpg" or $kzm = = "jpg") {//File filter
     if (!). Is_dir ('./'. $file))} {//folder filter
      $array []= $file//file name to be stored in array
      $i ++;//record total count
      }
 }} Print_r ($array);
? >

More interested in PHP related content readers can view the site topics: "PHP file Operation Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "Basic PHP Grammar Introduction Tutorial", "PHP operation Office Document skills Summary (including Word, Excel,access,ppt), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"

I hope this article will help you with the PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.