0

This a problem I already had twice while deploying an application online and that I've solved twice by chance still without understanding what caused the issue. This is the third time and it's still bugging me.

  1. I work locally with PHP files and Notepad++ (files are encoded in UTF-8 without BOM encoded btw). Everything works great here (config: easyPHP) without PHP errors.

  2. After uploading the files to a server, some files give me basic PHP errors like *unexpected T_FUNCTION in line 1* although there is no error in my code.

  3. I luckily happened to open the file with windows Notepad which gave me a hint: there are no spaces or line breaks between characters (this is why PHP gives me errors). To sum up:

File opened with Notepad++:

<?php
// Comment
function() { etc... (rest of the file)...

File opened with windows notepad:

<?php//comment function(){ ... which causes error online (but not on EasyPHP)

I've looked everywhere and done everything i could (adding line breaks in notepad++, converting to ANSI/UTF8, etc, but the file seems like corrupted or something). It is not a script I've copy pasted or anything, I create all my files by adding a new *.txt document in windows and renaming it *.php.

My questions:

  • Why would Notepad++ and windows notepad show me different line breaks ? Is it encoding issues ? Windows/UNIX interpreting files differently ?
  • Why would this work on my computer with easy PHP and not online ?

Thanks you in advance for any answer, if not, hint.

Romain Bruckert
  • 2,546
  • 31
  • 50
  • How are you uploading the files (ftp, http upload)? – Jeff Nov 29 '12 at 18:26
  • PS: my only temporary solution for now is to delete the corrupted file, to copy and another working PHP file and renaming itand retyping rewriting or copy pasting my code inside, which is obviously not a durable solution. – Romain Bruckert Nov 29 '12 at 18:26
  • @Jeff I'm uploading the files with FileZilla in FTP and have tried to use both passive and active modes. – Romain Bruckert Nov 29 '12 at 18:27

1 Answers1

2

If you are transfering your files via FTP to production server then the problem could be some ftp clients do automatic newline conversion.. check out transfering files with different ftp client or tweak it's settings to disable automatic ascii text new lines conversion .

UPDATE:
Yes it's probably your files are being transferred in ascii mode rather than binary, so the solution is to set Filezilla to transferred your files in binary mode, see here the actual settings https://stackoverflow.com/a/555003/352672

Community
  • 1
  • 1
Nelson
  • 49,283
  • 8
  • 68
  • 81
  • I've looked that way and used different FTP utils. I don't think this is the problem because i notice a difference already on my computer (without any upload) if the file is opened with Notepad++ end if opened with Windows Notepad. Besides, not all files have the problem (like 3 on 800, depends). – Romain Bruckert Nov 29 '12 at 18:32