A 777 permission on the directory means that everyone has access to read/write/execute (execute on a directory means that you can do an ls of the directory).
755 means read and execute access for everyone and also write access for the owner of the file. When you perform chmod 755 filename command you allow everyone to read and execute the file, the owner is allowed to write to the file as well. So, there should be no permission to everyone else other than the owner to write to the file, 755 permission is required.
Hope this helps you!
To learn more about Linux, it's recommended to join Linux course online today.