Month: September 2007

PHP : Strip or find a file extension

Getting a file’s extension is essential when working with uploads and other manipulations complying with files. You might have a user uploading a file and you need to rename the file before moving it from the temporary upload directory. In order to do so, you can obtain the file extension and then rename it to whatever you like. Below is a custom function I wrote which will help you to get the extension of any file using PHP. function stripExtension($filename = '') { if (!empty($filename)) { $filename = strtolower($filename); $extArray = split("[/\\.]", $filename); $p = count($extArray) - 1; $extension = $extArray[$p]; return $extension; } else { return false; } } So basically, we split the name of the file on every dot (.). The PHP split() function creates an array of strings for us. We then take the string obtained after the last dot (.). Even though there might be more than one period within the filename, we know that the last string will be the extension. Now, with the full file extension in your possession, you can continue and use it for something specific. I hope that you found this...

Read More

WordPress Pagination Class

I wrote a simple, yet extremely useful WordPress pagination class. The class is not complete yet, and I work on it as I move along and need new features or actions. So you have the freedom to take the class and customize/expand it as you might need to. First off, you can download the class below : WordPress Pagination Class In order to use the class, you’ll need to include the class file. With the class file included, you can initialize the class and then execute the startPaging() class method. Before you execute the method, you need to specify some variable values. See the example below : include_once(ABSPATH . 'wp-content/plugins/yourplugin/class.pagination.php'); $tableName = $wpdb -> prefix . 'yourplugintable'; $tableFields = '`id`, `title`, `description`'; $pagination = new Pagination($tableName, $tableFields); $pagination -> perPage = 10; $pagination -> pluginUrl = '?page=yourplugin.php&'; $allRecords = $pagination -> startPaging($_GET['wpMailinglistPage']); From there, you can simply loop through your records with a foreach(); or something similar to output the records. In order to output the page numbers/links and the “previous”/”next” links, you can echo the pagination(); class method. See the example below : Good luck! I hope this is useful! Please feel free to post your updated source code, ideas and...

Read More

WordPress Mailing List v2.0

The WordPress mailing list plugin v2.0 has been released to the public with a great set of new features. These features include : Multiple mailing lists Email scheduling Newsletter templates Automatic updates indicator Improved sidebar widget with Ajax Post/page opt-in form embedding Email queue CSV and MacOS Address book importing Excel CSV file exporting And much, much more… If you are upgrading from v1.X, you immediately get 25% discount upon...

Read More

Countries SQL Code

I know that I was looking for the necessary SQL code to create a countries table, together with the necessary queries to insert all the available countries into this table, each with a unique ID key. So I decided to create it and I’m sharing it with the rest of you whom might need it. See the attachment below. Countries SQL...

Read More

CakePHP : Delete multiple records

With CakePHP, you can remove multiple records from a database table using the deleteAll() model method. deleteAll() Usage $this -> Model -> deleteAll($conditions, $cascade = true); Lets say that you wanted to remove all the records for a specific user from the Item model. Below is a quick example. deleteAll() Example $this -> Item -> deleteAll(array('Item.user_id' => 13)); …where 13 would be the ID of the specific user. Off course…you can completely truncate a table with the same method, this time removing all conditions. Below is an example of how to truncate a database table using CakePHP. deleteAll() table truncate $this -> Model ->...

Read More

Pin It on Pinterest

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!