James Revillini

Say 'no' to styrofoam.

Tag: php

Parse an uploaded CSV file in 2 lines in PHP/CakePHP

Nasty but gets it done:

or, if you want to be even more crazy, in 1 (note, config options are inline but I left the assignments so they are findable):

or, if you want it to be one expression, but more readable:

In the examples above, I’m assuming you already know the temporary name of the uploaded file. In regular PHP, you could prepend this code with

In CakePHP, you might just replace $tmpname with $this->data[‘Whatever’][‘csv’][‘tmp_name’];
This kind of assumes you had done something like this on the form page:

CakePHP mutliple checkbox input

This is just here because I always forget how to do it:

[code]echo $form->input(‘fieldname’, array(‘options’=>array(‘1’=>’val1’, ‘3’=>’val2′ […]), ‘multiple’=>’checkbox’, ‘label’=>’Da Label’));[/code]

PHP Script: Convert Excel or tab-delimited file to html table

Here’s a script which I wrote today while on the jorb.  The purpose was so that someone could copy and paste from an excel spreadsheet into a textarea, click a button, and voila: an html table.

The nice thing was that when I pasted Excel data into the textarea, it was tab-delimited with line breaks.  At that point, all I needed to do was some replacements and throw a table wrapper on it.

Here’s the code for the conversion function (sorry – i haven’t installed a php code parser yet to style this more nicely):

* convert tab delimited file to html table
* @input string tab-delimited text
* found at http://james.revillini.com
* note: you are not required to keep the above copyright notice in this code.
function tabs_to_table($input) {
//define replacement constants
define(‘TAB_REPLACEMENT’, ‘</td><td> ‘);
define(‘NEWLINE_REPLACEMENT’, ‘</td></tr><tr%s><td> ‘);
define(‘TABLE_BEGIN’, ‘<table><tr><td> ‘);
define(‘TABLE_END’, ‘</td><tr></table>’);</code>

//replace all tabs with end-cell, begin-cell
$input = preg_replace  (’/\t/’  , TAB_REPLACEMENT  , $input);

//split the list on linebreaks
$rows = preg_split  (’/\r\n/’  , $input);

//replace all linebreaks with end-row, begin-row (with or without altRow class)
$output = ”;
foreach ($rows as $index => $row) {
$output .= $row . sprintf(NEWLINE_REPLACEMENT, ($index%2?”:’ class=”alt”‘));

//build table
$input = TABLE_BEGIN . $output . TABLE_END;
return ($input);

SwfUploadComponent: A CakePHP Component for Handling File Uploads

I recently published an article at The Bakery which explains how to incorporate SWFUpload into your CakePHP application. SWFUpload is a fantastic javascript/flash library which facilitates multiple file uploads with real-time upload progress.

The article includes the SwfUploadComponent as well as usage tips. I developed this component because I needed to handle uploads which could be associated with any number of objects in Mango. One of the key goals of Mango is to be user-friendly, and since file uploading is one of the least fun experiences on the Web (in my opinion, anyway), I needed to find a way to at least simulate the kind of user interaction that the desktop operating system offers. SWFUpload meets that need.

I’m working on a project page for SwfUploadComponent which will have the API for the component. Stay tuned.

Thanks to Eelco Wiersma for the original code which I used as a basis for development. Also, thanks to gwoo for guidance and cakebin pastes – he helped me to tweak it for performance and readability.

Mango Initial Release Draws Near

I’ve fixed most of the major bugs, and moved a few ideas I had to the next release wish list. As a final step, I must complete the help files. I plan to take care of that over the weekend and release a working copy within the next week.

March 2007 Mango Status Update

The Mango Initial Release is drawing near. I’ve resumed work on the project I was getting all fired up about last year – thanks to my wife – and it’s looking really good.

A few things about the plan have changed, however. First, I decided that for now, I’m just targeting me as an audience for this thing. Trying to program it in a way that would work for the whole world was stressing me out and slowing down development. My wife snapped me out of a funk one night when I was lamenting my predicament by asking, ‘Why don’t you just make it for you and don’t worry about selling it?’

It was the best advice I ever listened to – it made me remember why I started this. I suddenly knew the direction I wanted to go in. I got my spark back.

Thanks, Lovie.

This doesn’t mean that Mango is dead or anything. I’m still going to release it to the public under one of the open source licenses, but whether or not I try to turn it into a money making adventure remains a question that I’m not too concerned with right now. Right now I’m excited because I’ve got the following features in there now:

  • WYSIWYG editor – TinyMCE
  • Multiple file uploads with progress bars for each file – SWFUpload
  • Multimedia attachment to Pages – Anarchy Web Player (not sure if I’m staying with this or if I will roll my own)
  • Full YAHOO UI integration for a great look and feel and intuitive, responsive interfaces.
  • A basic authentication system
  • All the usual stuff that wikis have.

I still need to have a search feature, but I might leave that for the second realease. Mostly, I’m trying to concentrate on the most important part: making editing pages easy and fun. I need to run through things tomorrow and figure out what needs to be locked down better. I’m sure I’ve got security holes in it right now. once I plug those, I’ll put it online and start checking in new versions periodically as I reach stable milestones.

It feels really good to be working on this right now. My wife has been very supportive, which helps a lot. Almost every day I come home, put down my stuff, crack open the laptop, and start hammering away at it. I’ve even gotten the alias ‘Wiki-man’ recently.

Mango – a wiki for the rest of us

This weekend, I’m hoping to release a beta of a wiki system I’m developing called ‘Mango.’� My intention is to start off with some basic wiki functionality, get some testers, revise, then produce a version 1 release which will be available for free download on the web.

Ultimately, I would like to do a full product launch a month or two from now which includes a boxed version of this software.� The commercial, packaged version will include the Mango software, printed and digital user manual, and video tutorial cd-rom and/or dvd.

I will be hosting a live version of Mango at http://mango-demo.revillini.com.

I will also host my family wiki using Mango at http://family.revillini.com – this was the original intent of the software, even though it does not yet have any geneology-specific features at this time.

© 2017 James Revillini

Theme by Anders NorenUp ↑