I am using WinSCP to transfer files to an FTP site. I have a situation currently where one specific file within a folder loses all of its formatting when it is uploaded causing the PHP file to no longer work.
All other PHP files within the folder work correctly when uploaded.
I can't understand why just one file could be affected in this way. Can anyone shed any light on the situation?
The file was probably transferd via ASCII mode which will modify the encoding and the line endings of the file.
As you have not stated what exactly do you mean by "losing formatting", it's difficult to answer, anyway:
As per src's answer, if the line endings change due to ASCII/text mode transfers, the resulting converted file can be perceived as if it lost formatting, if opened in an editor that does not support the target line endings. Though that hardly explains why there's only one affected file. Although can WinSCP technically choose a different transfer mode for example based on a file size or modification timestamp, if configured so, I doubt you did. Also note that WinSCP defaults to binary transfer mode. It would help if you state what transfer mode do you actually use with WinSCP. Definitive source for this information is WinSCP session log file. Also sharing relevant part of a log file would also help with investigation.
Another possibility is that the affected source file was created with a different line endings in the first place (like in a different editor than you use usually). As such the problem would have nothing to do with transfer mode, or WinSCP. And the difference is possibly revealed only after you open the files using a third editor on the remote side that supports only one of the line ending formats.
Though in both of these cases, the file should still work in PHP, as PHP supports both Unix and Windows line endings. Possibly the source file has such a strange format that during ASCII/text mode transfer, the server got confused and converted the file incorrectly. But that's just a wild guess.
Again, we need more information to help you.
Related
What I have to be able to do is copy an entire folder from a remote source to the local server executing the PHP file. I can do that fine except for one problem, PHP files. Obviously, I can't just go copying the source code of a PHP file using regular commands as they will interpret the code and give me the returned stuff. What I have to have is the code. Is there any way to do that?
Hope I'm clear enough, my problem isn't something very hard to understand, I just want to know if it's actually possible. If not, maybe someone may have an idea of an optimal way of storing the source code alongside the executable php? I was thinking simply saving it as text when I'm done developing but if there is a way to do it completely automatically then that would be much more awesome. Best case scenario, I can just copy the folder with php files and then execute it from local. I need to know if that's even possible... Worst case scenario, I have to duplicate files in order copy the text version of them to the local server and discard the php ones since th e executed files are not relevant to my program. I don't want that, but I just don't know if PHP is able to do what I want.
Edit: sorry for not specifying! I am the admin of the remote server and have total access. I can and was expecting to make a php file on the server itself. That's the kind of system I have at the moment! I zip a folder and return it when requested from my local source. My only problem is the php executing.
You cannot do that unless you:
have FTP access (or anything else that is not HTTP-based)
have access to a script on the server that is designed to return the sourcecode of a given file
use an exploit such as the ?-s bug in the CGI SAPI
So you are most likely out of luck.
I edited a bunch of PHP files (with N++) on Computer A, uploaded it to a server, downloaded it to computer B (with N++), and they lost all their line breaks. I've done this routine many times and never had this problem.
I've tried
EOL Conversion
Opening in different text editors
Search/replaces
Everything I found on Google/SO
Open up the file in Notepad++, choose Edit -> EOL Conversion -> Windows. I kept having this problem and somehow it had been set to Mac. Transferring in binary mode worked, but it was a hack. This is better.
There seems to be a question missing?
If you want to format it, you might just want to let a code-editor that knows indentation (auto-formatting) fix it for you. Eclipse can, I'm sure netbeans can too.
I think eclipse auto-formats everything you paste automagically, but otherwise just find the formatting commands ;)
im trying to implement on my site a system who let the user download a file that have to be change before the download.
I have a master file (a .exe program), that inside have a variable who has to be change for every different user.
The most simple solution is to change a variable inside a xml file every time the user want his personalized exe and then make the exe file to read the external file. BUT i dont want the user to download more than one file.
Is this possible? using php can i change a parametter inside a compiled program? Thanks for any help and suggestions!
If you really really know what you're doing and you know exactly the bits that need to be flipped inside the file, then yes, it's possible to modify the .exe file with PHP. Otherwise you have to make changes to the source or other files the .exe is built with and compile the program on the server before sending it to the user.
In theory it's certainly possible (PHP is turing complete), but as stated in other answers it will be hardly worth the hassle (considering the fact that you have to ask whether it is possible shows you'd have to investigate at last for days into the standard exe-format).
I'd recommend one of the following:
1) Zip the program with the configuration file; either use a separate launcher (e.g. Java [a JAR is a ZIP file]) or add a configuration file that is read by the program itself. There is a number of PHP libraries for generating ZIP files.
2) compile the program with the changed source on the server itself; however this can also become quite complicated depending on your server configuration and the programming environment you use. If you have never administered a virtual server I would not even slightly recommend that as an option.
3) If you can assume that the user got somewhat stable Internet access you might also consider to let hir download a standard executable, where additional configuration will be downloaded later on by the program itself (e.g. by transmitting the username to the server). However this creates dependencies you might want to avoid (your user probably can't use it on machines without Internet access and you should assert that your server is up most of the time).
While it's probably possible, I doubt it's worth the hassle. Unless you're trying to fight piracy or something. Why don't you just serve the user a custom .zip file with the .exe and a config .xml?
[edit after OP commented]
I presume what you're trying to edit is the facebook ID/username? Well, try to compile the base file with some unique string like "THISNEEDSTOBEREPLACED", then use some binary safe function to replace it. Though remember things can and will get tricky if the string lengths don't match.
I allow PDF files to be uploaded to my site (PHP).
I would like to offer the ability to also allow .zip files which contain PDF files in directories so it is easier for users to simply zip a directory and upload one file instead of uploading multiple zip files individual.
For those of you who offer a .zip file upload feature to your (PHP) website, what are the technical, security, and other issues you have faced?
Be careful how you unpack the zip, you could find yourself consuming far more resources than you expected. Perhaps some setrlimit(2) resource limits before unpacking would be wise.
The unzip(1) utility has several nice safety features built in; the -^ command line option turns off control-character filtering, so make sure you don't touch this :) and the -: command line option allows stupid pathnames like ../../../../etc/passwd. Make sure you're on at least version 5.50, so that those stupid pathnames are forbidden by default. (And don't use that command line option. I mention the options just so you can more easily find the documentation for them. :)
If you use an API, make sure it has options to prevent both kinds of silly filenames.
Assuming the .zip gets unpacked eventually you would have to make sure the directory they get unpacked in is unreachable by the the clients' browsers (with .htaccess or by placing it outside the web root directory), and even in that case I'd still monitor the contents of the unpacked .zip to make sure they didn't contain anything that might prove harmful (php or other files run by the server, html spoofs).
Another issue is i guess the upload_max_filesize set in php.ini, you can make sure it can be set big enough to suit your purposes before you start coding.
edit: also read sarnold's answer ;)
AFAIK, php can handle zip files pretty efficiently. Difficulties/Issues that I can think of is, while accessing the file where We need to extract the zip first, and then retrieve the actual needed file. Due to that reason, extracting a zip, might consume additional amount of server time, depending on the size of the file itself.
Where As, during uploads, I do not suppose there is any difficulties or issues specially emphasized on zip types.
When I upload/download some HTML/CSS/… file to FTP server, sometimes something puts every line of code in one line making it completeply unreadable. That something happens every now and then and I’m still looking for an explanation for this behaviour. What could cause this?
It has to do with text file line endings and FTP transfer modes.
Text files in Windows use a combination of carriage return and line feed at the end.
Text files in Mac OS9 and down use carriage return only.
Text files in UNIX and its clones (including OSX) use line feed only.
It sounds like you're pulling a UNIX-style text file to a Windows system in binary mode and then trying to view it in an editor that doesn't understand these differences.
FTP clients have an ASCII (or ASC) transfer mode to do these conversions for you. It's not usually turned on by default, though, as it messes up binary files.
Two solutions are to use an editor that understands the differences or use an FTP client that allows you to tell it that specific file extensions should be transferred in ASC mode.
P.S. This is probably better asked on superuser or serverfault.
This problem arises when we are working with Notepad++, Notepad editors, main importantly hosting servers. I had an same issue and fixed it by opening file again through Dreamweaver and set the content properly and uploaded to server Again. Works fine.