• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

PHP: Download unparsed .PHP files?

LeetestUnleet

Senior member
So I'm working on a project that basically needs to download a cloned copy of some PHP source files in a directory. I *could* rename the extensions on the server side then rename them on the client side, but that seems highly inefficient.

I was thinking I could use an SSH socket within PHP and send commands that way, but I have no idea how to go about working out that communication. I notice that fopen() can support SSH wrappers with an extension, but we're running the client on standalone Windows/Apache machines so we can't exactly recompile PHP.

Any thoughts?
 
couldn't it be as simple as fopening the .php file and writing it's contents to the browser with a txt or .php mime type?
 
Can't you use FTP?

Some alternatives:
a. Client grab using FTP
b. server package files into an archive (zip, tar) and send that as HTTP response
c. one script page sends another as a HTTP response, as text/plain

If you control both the client and server, FTP is probably easiest and programs like CuteFTP allow setting up batch jobs.
 
I have full control over the client and the server. Both are setup with Apache/PHP (the client is actually just running a simple xampp installation). As part of the synchronization process between the server and the client, the client clicks a link within one of its own pages, which connects to the server and pulls down the database and updated .php files located in the directory. So it needs to be done *within* PHP code. I'll look into the MIME headers and perhaps maybe an FTP connection later, though that doesn't mean I won't mind more suggestions 🙂
 
Originally posted by: troytime
couldn't it be as simple as fopening the .php file and writing it's contents to the browser with a txt or .php mime type?
This makes the most sense to me as it looks pretty simple. Just have a page that takes other pages as an arg:
getcode.php?file=/some/other/script.php

Be careful of the myriad of security issues with that of course.

Like others have said too, if you can keep a differently packaged version of the source on the server, then you can download it via http without anything fancy on the server side. Eg. keep a copy of all the source in a tarball on the server or make a copy of each file, renamed to foo.php.txt.

Involving a second protocol, like ftp or scp seems needlessly complex, imho.
 
Yeah, just send the content by setting the mime type and headers. No need to make it overly complex like others have said.
 
Back
Top