I'm about to get my hands dirty writing an FTP wrapper for PHP, I just need to perform the basics:
read / write and append to files
list / chmod and delete files / folders
Unfortunately I only had to mess with FTP within PHP once to answer this question, and I got somewhat disappointed with the ftp extension, mainly because it ain't trivial to distinguish between files and folders and the overall speed wasn't great.
As far as I know PHP has four distinct ways of interacting with FTP servers:
Pure Socket Implementation
File Wrappers
FTP Extension
CURL Extension
Now, I don't want to code the FTP client protocol myself, so option #1 is out of the equation.
File wrappers are great if I need to do something trivial like getting a single file, but they are extremely slow if I need to perform more complex operations since each call will open its own connection.
That leaves me with the FTP and CURL extensions, and here is where I need some guidance. As I said before I am not a big fan of the FTP extension, on the other hand I've never used CURL to FTP so I can't objectively compare one with the other.
Has anyone ever tried both approaches? What are your thoughts on them? Is the CURL option faster?
Also, are there any alternatives I'm not aware of?
Have you looked at the PEAR package Net_FTP?
I've tried both for one proj. Was needed to upload some file via ftps+auth connection with encryption and authentication then to get response code and XML info, kind of XML-RPC exchanging so at the end could not even come closer to the solution with php-ftp-extension and everything was accomplished with some debugging (CURLOPT_VERBOSE) and configuring with PHP-CURL. So I vote for CURL, it is from 1997-th and works great!
Related
I just wanted to keep all my code libraries (PHP Classes; ex: http://libraries.com/form.php) on a single server for easy maintenance and availability. Wherever I need to use this library; I'd just include it in my code. But; I know; enabling remote URL include isn't safe at all. So I found a work around.
I'd just use eval( file_get_contents( 'http://libraries.com/form.txt' ). I use .txt instead of .php so I get PHP code as it is; not a blank file returned by server after PHP is processed.
This works; I get my PHP library/class and I can play with it on a remote location. But I don't know if it is safe or not. What could be pros and cons of this way. Or what other way you can suggest me to achieve this safely?
This:
Has all the security downsides of includeing remote files
Is massively inefficient due to all the extra HTTP requests
Means that a new release of a library gets deployed without being tested against the rest of the code in an application
Adds an extra point of failure for the application
Don't do this. It is a terrible idea.
Installation of dependencies should be a feature of your install script, not the application itself.
I wrote a script in php that allows me to get a list of files in a directory as an array, parse each one for a particular string, and then it displays all of the files that contain the search string.
My IT staff won't let me install php on the server though. Can this be done with javascript without ActiveX? Everything I could find on this is pretty old.
Alternatively, is there a way to make php functions like opendir and readir work on a remote server?
Thanks
Nor JavaScript / ActiveX will help you do what you need to do if the directories are on a remote server. So no, can't be done.
This would be quite the security violation if you could. You will need to have something installed on the server that has file system access. If this is on an internal network, you may be able to simply enable directory browsing... but there aren't any client-side-only solutions to this.
I am interested in finding the most reliable method for uploading files in PHP. I need a progress bar with the upload.
I have tried SWFUpload but it randomly issues an I/O Error. Even if the same file is uploaded sometimes there is an error and sometimes there is not. I have configured all the necessary INI/Mysql/Apache directives to accept large file uploads.
So, I am looking for alternatives as a Flash based solution has not worked. Would Java be more reliable? I have also looked into PHP with APC.
I definitely cannot afford these random errors, so any help on reliable software / suggestions on how to minimize them would be appreciated.
Thank you.
There are other flash based solutions other than SWFupload. Have a look at uploadify.com
I haven't come around to try this myself yet but http://www.plupload.com/ might be what you're looking for on. But otherwise PHP + APC works good as well.
I am assuming 2 things here:
1) Some kind of client will be doing the file upload
2) You get some kind of say on what the client installs on their computer to help make this happen.
If this is the case, my first suggestion would be:
Give them FTP or SFTP client software to upload files. The php page you make can have a link to Filezilla, along with instructions on how to use it. ftp and sftp are THE protocols to use for transferring files. HTTP is just not designed(well) for it, nor are browsers.
Is it possible to do file operations from a script running on a different server than the files being operated on? That is, upload, move, rename, delete, create new, modify, etc.
How would I go about doing this?
As far as I know, it can be done only by logging into the shell via the remote script and then executing the commands from within the shell, or maybe by using FTP from the remote script.
Another method would be:
Create scripts in the server which will accept parametres (POST data) and do operations based on the arguments that are supplied to it.
One way do to it would be through FTP.
You are basicallly describing WebDAV, which was created so that write-methods like those found in ftp could be done over HTTP.
I imagine it would be tricky to make a non-http file manager with PHP that was save and reliable.
There are several libraries for adding making WebDAV feasible in PHP, not that are core or standard extensions yet, though.
yes, this is either possible through php’s ftp functions or the native file system functions.
i wrote one myself (myftphp <-- advertisment :D)
using the native filesystem functions there are always restrictions on permission management, but for managing files in a public directory it’s perfect
See http://rosefinch.sf.net
A open source php file manager.
There is a fantastic remote filesystem manager available.
Just have a look at Flysystem.
It requires PHP 5.4 or higher.
For years, I've been investigating how to create music streams from my computer. I've seen programs, but anything useful I've seen is Windows only (I use a Mac).
Eventually, I got interested in how streams work. Is there any way I could create my own stream, possibly using socket functions in PHP? Is there a PHP library for this?
Take a look at Ampache. It is a Web-based Open Source Audio file manager. It is implemented with MySQL, and PHP. It allows you to view, edit, and play your audio files via the web.
In the end it all boils down to the protocol you'd want to use. Shoutcast IMHO is plain HTTP, so to make your own stream, you just output the streams content.
To make an ogg based webradio work with my Sonos system, I have created a little transcoding wrapper around sox which is is actually written in PHP, so it may be helpful to you to serve as an example.
You'll find it here: http://www.gnegg.ch/ogg2mp3/
If you are after implementing your very own streaming protocol - maybe even UDP based, then, I'm afraid, PHP may not be the right solution for the problem - at least not as long as it has its share of problems when used for long running processes (which 5.3 may bring some help for with its integrated garbage collection)