开发者

PHP Parser Error When Viewing Same File Saved in Windows

开发者 https://www.devze.com 2023-02-26 04:45 出处:网络
I have a PHP file for my website, index.php, which, as it stands on the server, it works correctly, no errors triggered and the page loads as it should.

I have a PHP file for my website, index.php, which, as it stands on the server, it works correctly, no errors triggered and the page loads as it should.

The server is a Linux server running Apache, and my local machine is a Windows machine. Using the FileZilla Windows client, I download index.php and open the file in Notepad++ in Windows. I save this file in Windows, and then upload and overwrite the file on the server. The page now does not load, with this error on the page:

Parse error: syntax error, unexpected $end in /path/to/my/site/index.php on line 1

I've Googled this error quite a bit, and all of the answers I've come across detail that it's either a PHP short tags problem (replacing <? with <?php, but the file does not include any short tags) or a stray bracket somewhere in the file (but I've checked and all brackets are correctly matched). Besides, I do not touch the source itself, and simply save the file after opening it, so since it works before but not after the local Windows save, I have to believe it's a line-ending problem between Windows and Unix.

What is even more puzzling is that I was able to create a test.php that开发者_JAVA技巧 just called phpinfo(), and saved it in Windows and uploaded, and the page correctly loads when I call it from within my web browser. The problem must be related to how Notepad++ translates a non-Windows created file with Unix or Mac-based line-endings to Windows line-endings, and it somehow gets clobbered.

Any ideas? I'll try to provide more information if I've omitted anything, but I really don't think the source is required here.


Try setting transfer type to BINARY instead of TEXT in your filezilla client. This might be an issue with transfer encoding rather than notepad++ as I have faced a similar problem earlier which was resolved by forcing transfer to binary.

0

精彩评论

暂无评论...
验证码 换一张
取 消