PHP PathInfo () Get the file path, name and other information _php tutorial

Source: Internet
Author: User
Suppose you now have a picture file whose server-side path is:

$path = "/www/mywebsite/images/myphoto.jpg";
1.pathinfo () function
The PathInfo () function returns an array containing the file information, with four elements, dirname, basename, extension, and filename, respectively. Print the code for the array:
Copy CodeThe code is as follows:
$FILEARR = PathInfo ($path);
Print_r ($FILEARR);
Output: Array ([dirname] =/www/mywebsite/images [basename] = myphoto.jpg [extension] = jpg [filename] = m Yphoto)

This allows us to obtain the corresponding key value based on the key name of the array:

Copy CodeThe code is as follows:
echo $fileArr [' filename '];
Output Result: Myphoto
echo $fileArr [' extension '];
Output result: JPG
//...

2.dirname () function
The dirname () function gives a string containing a full path to a file, and the value returned removes the directory name after the file name, which can be considered an extension of the PathInfo () function:
Copy CodeThe code is as follows:
echo dirname ($path);
Output Result:/www/mywebsite/images
Or
Echo dirname ("/www/mywebsite/images/");
Echo dirname ("/www/mywebsite/images");
The result of the output is:/www/mywebsite

So it can be understood that the returned value is the previous level directory address name of the path.
3.basename () function
The basename () function gives a string containing a full path to a file, and the value returned is a basic file name, which can also be considered an extension to the PathInfo () function:
Copy CodeThe code is as follows:
Echo basename ($path);
Output Result: myphoto.jpg
Or
BaseName ("/www/mywebsite/images/");
Output Result: Images

So it can be understood that the return value is the name of the path of the current directory.

http://www.bkjia.com/PHPjc/324253.html www.bkjia.com true http://www.bkjia.com/PHPjc/324253.html techarticle Suppose you now have a picture file whose server-side path is: $path = "/www/mywebsite/images/myphoto.jpg"; The 1.pathinfo () function pathinfo () function returns a file containing a letter ...

  • 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.