Well it has been some quite since we were talking about creating new and excited projects, and well I want to share this “snipet” with the communtity.
So, we are talking about using a similar function in PHP that could be the equivalent to wget, and as I am not a full time PHP programmer I ignore wheather this function could perform the same task as the wget in shell for linux usage (I mean in performance).
I will start pointing at checking what your PHP settings have already enabled, this can be a tricky part in the process. We will be using fopen() and so it can load local files and URL files.
But pay attention since fopen() opens the files in text mode, so it means you have to enable the bytes mode to avoid further problems, for example when transfering files like zip or exes from server to server it won’t be any problem.
First things first, you need to open a file using fopen or in our case to open a url:
$referencia=fopen("http://www.somesite.com/file.zip","rb")
Now once it is fopen() it DOESN`T mean it is already really opened, it just means we are taking a file into consideration, now how we really open a file is by doing the next sentence:
$contenido = stream_get_contents($gestor);
This way we are now getting the contents of the file for further analisys. Now be sure of “closing” the refered file:
fclose($referencia);
Now open another reference to file (to prepare it to store the contents previously gotten)
$mfile=fopen($nombreArchivo,"wb");
Then send the contents previously gotten and close reference.
$ecrit=fwrite($mfile,$contenido);
fclose($mfile);
Now you can implement this little version of wget to get things into your own server, and is fully working and compatible with the latest AMFPHP version
regards!













This post has no comment.