Path Separator of PHP in windows and LINUX

Source: Internet
Author: User
Welcome to the Linux community forum and interact with 2 million technicians. We all know that windows is compatible, while LINUX is running normally locally. After uploading to the server, the image is not displayed. The image link is the absolute path var ..., but I remember that this path has been processed as a relative path.

Welcome to the Linux community forum, and interact with 2 million technical staff> as we all know, What Is \ and/in windows, while what is in LINUX is/running normally locally in the program, after uploading the image to the server, it is found that the image is not displayed. The image link is the absolute path var /..., it contains \, but I remember that this path has been processed as a relative path.

Welcome to the Linux community forum and interact with 2 million technicians>

As we all know, What Is \ and/in windows, while what is in LINUX is/

The program runs normally locally. After being uploaded to the server, the image is not displayed. The image link is the absolute path var /..., it contains \, but I remember that this path has been processed as a relative path.

$ Path = dirname (_ FILE __))).'\\';
$ Search = array ($ path ,'\\');
$ Replace = array ('','/');
Return str_replace ($ search, $ replace, $ this-> tempfolder). $ this-> filename_prefix.#public.'.jpg ';

As you can see, the first line of code is used in LINUX.

The solution is to use the PHP pre-defined constant DIRECTORY_SEPATRATOR to replace path delimiters like '\' and '/'. In the past, I thought that since windows and LINUX support/, they all use, this is correct. However, we can see from this example that it is dangerous to process the path string, so it is best to use DIRECTORY_SEPATRATOR.

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.