Missing newline characters when uploading PHP files using FTP software

Source: Internet
Author: User
Tags php source code upload php

When using FTP software upload to download PHP source files, we occasionally found in the local Windows notepad++ editor written php files, after using FTP uploaded to the linux server, the PHP file line break all lost, resulting in PHP file does not work properly.

This time, again through the FTP software to download the php file just uploaded to the local windows, opened with the notepad++ editor, found that the PHP source code into a line, lost line.

What is the reason for this situation? Floating easy to summarize under a sentence:
because the Linux next line is \ n, and Windows next line is \ r \ n, when the FTP software uploads, the default is to upload ASCII, and ASCII upload file has a feature, will be in the file of the new line characters to appropriate processing to meet the environment of the upload server. In this process, some files will be handled improperly, there is a loss of newline character bug. (Note that not all PHP files are part of the PHP file that will appear this problem).

The issue of appeal, especially in the PHP source code with a single-line comment "//", will cause the PHP source files directly can not be run. Since the source code becomes a line, the single-line comment will comment out all the code behind//.

FTP upload Bug Resolution:
Method 1: Change the single-line comment///// to multiline comment/* Comment text * * this will not affect the execution of the subsequent source code even if the newline character is lost. (But it's still a headache to download to two local changes!) )
Method 2: ftp upload PHP files do not use ASCII mode, all using binary mode. This is the most insured. How to set the FTP software to binary binary mode binary upload, please network search under their own use of the FTP software settings.


" knowledge Supplement: ASCII and binary transfer modes for FTP ":

FTP has ASCII and binary two modes of transmission:
Binary mode does not perform any processing on the data.
ASCII mode converts the carriage return line to the return character of the native.


Because Windows and UNIX do not have the same line terminator. So ^m may appear when you transfer text files to UNIX from Windows with binary transfer. Similarly, when you transfer files from UNIX to Windows in binary mode, you may also see an incorrect carriage return line display.

New ftp_ascii.txt content under Windows is as follows:

Hello word!
Windowd to UNIX!
TEST FTP ASCII;


We upload them to UNIX in two different modes.
ASCII mode OK

VI Ftp_ascii.txt
Hello word!
Windowd to UNIX!
TEST FTP ASCII;


Binary mode binary problem

VI Ftp_ascii.txt
Hello word!^m
Windowd to UNIX!^m
TEST FTP Binary;

We can use ASCII mode to transfer text to avoid ^m problems in transmission. Although the ASCII mode in FTP can avoid ^m problems. However , in most cases, binary mode is chosen, which guarantees that the content of the transmission will not be changed. Especially in the transfer of executable files such as PHP source, most of the binary mode.

In FLASHFXP, you can select ASCII, BINARY, and auto three modes in the transfer mode, menu-----session.

In addition, we can also avoid the problem of lost lines when uploading files in the form of SSH login to sftp .

Missing newline characters when uploading PHP files using FTP software

Related Article

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.