PHP getting parse error: syntax error after uploading file with Filezilla

I wasted about an hour with this issue today so hope to save time for someone else or even me in the future by posting it here. I completely debugged a file in PHP, but kept getting errors in PHP saying that there was a syntax or parse error of some sort or another.

The Solution:

The solution was to simply go to FileZilla and use the top toolbar to navigate to Transfer/Transfer type/binary and problem solved! You can read on if you wish, but if you just want to fix it and continue working as I often do, feel free and stop reading here.

Here is an excerpt I got from http://stackoverflow.com/questions/5704224/php-parser-error-when-viewing-same-file-saved-in-windows:

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

asked Apr 18 '11 at 14:17
Mattygabe
98711329
1
Reproduce the problem with an as simple source file as possible. Once you've done that and still can't see anything wrong, look at the file in a hex editor to see exactly what is going on. You seem to be contradicting yourself in that you assume it is related to Notepad++ but at the same time claim the file is unmodified. If you have modified it with Notepad++, the first thing that comes to mind is a hidden unicode watermark at the beginning of the file (which you'll definitely see with a hex editor). Good luck! –  gamen Apr 18 '11 at 14:41
@gamen thanks for the response, and while I was thinking the same thing that it was somehow a hidden character like the unicode watermark, I checked and there was no such thing. Notepad++ was correctly saving the file, the issue is how Filezilla was transferring the file (as ASCII instead of Binary). Thanks for the help! –  Mattygabe Apr 18 '11 at 14:47

1 Answer

up vote 1 down vote accepted

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.

answered Apr 18 '11 at 14:40
That was the issue! FileZilla was set to "Auto", so at some point it must've been choosing "ASCII" instead of "Binary" when transferring files, and that was where the file was getting clobbered at. Great catch! –  Mattygabe Apr 18 '11 at 14:45

2 thoughts on “PHP getting parse error: syntax error after uploading file with Filezilla

    1. If you're talking about making a WordPress website responsive, there are a few good responsive themes you can use that do most of the work for you. If you want custom work done, you can hire an expert like myself to do it for you. I can do WordPress or non-WordPress responsive design, so let me know if you'd like an estimate.

      Actually for WordPress responsive design, I usually use the "responsive" theme which you can get free from wordpress.org. A lot of times, I'll locate on old version of repsonsive that has fewer features and can be easier to customize. I like to find somewhere around version 1.2 or similar where it's not the first, but close. That way it will have most of the serious bugs fixed already and you can build on to it to make whatever you want. That is a great way to make your own theme rather than doing it from scratch. If you don't need to make a whole new theme, then I'd recommend using the latest version instead of course. If you want the latest version of the Responsive theme, go here:
      https://wordpress.org/themes/responsive/
      If you want an old version to customize, go here instead:
      https://themes.trac.wordpress.org/log/responsive/

      That should be more than enough information to get you going unless you don't know how to do it which, if that's the case, you can hire me! Good Luck! -Ian L.

Leave a Reply

Your email address will not be published. Required fields are marked *