Categories
PHP

Archiving Remote Files Using PHP

We can easily archive remote files on our server and put the archive for download by our users.

Here’s a code snippet:

It uses the ZipArchive built in class of PHP to archive the target file which is stored on a remote host. It reads the remote file using “file_get_contents()” function and uses the “addFromString()” method of the ZipArchive object to add the data as a local file inside the archive. The first parameter of this method is the name of the file which will be inside the archive. This file is usually called “local file”. The second parameter is the file contents in raw string format. Instead of the file_get_contents(), we could use alternative fopen(), fread() or fgets() functions to get the file contents as string. But when we have better and quicker solution, why should we go for complex ones ?

Enjoy 🙂

Categories
PHP

PHP-GTK: App to update Twitter

People who have been in touch for a while might have noticed how much twitter addict I have suddenly become. Today, I wrote a php-gtk program to update my twitter status. I developed it using php-gtk2 and cURL.

I was having a lot of troubles developing it. I was using “thread safe” php while GTK is “nts (non thread safe)”. I managed a non thread safe php5 but problems raised with the cURL library. The required dependencies for cURL and mysql were not available with that package. I had to copy those specific files from another package. Again, I was getting confused as the app failed to load cURL repeatedly though I had it enabled in php.ini. Later I found out that when I copied the dependencies, I have also copied a “php-cli.ini” which was substituting the default php.ini since php was running in the CLI mode.

Finally it’s done. I am still a beginner at php-gtk. I didn’t write the program from scratch. I copy-pasted some codes from my other projects and php-gtk manual. But this program is going to be a good source of inspiration for me. I really like php-gtk. I am gonna dig a bit deeper whenever I get some time to spare.

Download: http://masnun.googlecode.com/files/twitter_php_gtk.php

Categories
PHP

PHP-CLI: Expand Short URLs

This is a modified version of the code snippet available at: http://hasin.wordpress.com/2009/05/05/expanding-short-urls-to-original-urls-using-php-and-curl/#comment-68180

It’s a php command line tool to expand a provided short url.