June 30, 2004

File uploads in PHP

Writing a PHP page and need to accept files from a form? Here's the skinny, according to the PHP Manual entry on Handling file uploads:

First, you will of course need the HTML form:

<form enctype="multipart/form-data" action="_URL_" 
                   method="post"> 
   <input type="hidden" name="MAX_FILE_SIZE" 
                   value="30000" /> 
   Send this file: <input name="userfile" type="file" /> 
   <input type="submit" value="Send File" /> 
</form>

Then you'll need to save the file in the PHP page:

<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES 
              //should be used instead
// of $_FILES.

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . $_FILES['userfile']['name'];

print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], 
                           $uploadfile)) {
   print "File is valid, and was successfully uploaded. ";
   print "Here's some more debugging info:\n";
   print_r($_FILES);
} else {
   print "Possible file upload attack!  Here's some ";
   print "debugging info:\n";
   print_r($_FILES);
}
print "</pre>";

?>
Posted by roadnick at 11:47 AM | Comments () | TrackBack

June 28, 2004

Manipulating time and dates in Java

Need to get a certain date or time -- other than right now? Here's a hint: don't use java.util.Date. Use java.util.GregorianCalendar instead. For example, if you needed a date object that represented the moment twenty four hours ago:

java.util.GregorianCalendar lastAcceptable = 
         new java.util.GregorianCalendar();
lastAcceptable.add(java.util.Calendar.HOUR, -24);

You can use any of the constants defined in java.util.Calendar to add or subtract time from a date. Check out the GregorianCalendar API for more information on manipulating and retreiving dates and times.

Posted by roadnick at 03:08 PM | Comments () | TrackBack

June 27, 2004

How to format a date in Java

Creating a java.util.Date gives you the date all right, but if you need to format it in a particular way, say, for a database query, you need to use a formatter, such as the SimpleDateFormat class. For example, this code turns today's date into the string "06-27-2004":

java.util.Date theDate = new java.util.Date;
java.text.SimpleDateFormat dateFormatter = 
       new java.text.SimpleDateFormat("MM-dd-yyyy");
String theFormattedDate = dateFormatter.format(theDate);

You can format it any way that you like. Check out Customizing Formats for more pattern options.

Posted by roadnick at 02:56 PM | Comments () | TrackBack

June 26, 2004

The commodity network

With the way kids expect everything to be done for them, do we really have the creativity left in this world to take advantage of Decentralization and Commodification? I hope so.

Posted by roadnick at 01:01 PM | Comments () | TrackBack

June 24, 2004

Tip: Use XForms to send and receive Web services messages

Now on developerWorks, Tip: Use XForms to send and receive Web services messages: "One of the great strengths of XForms is the fact that an XForms client can send its data as XML, and that it receives XML in return. This capability can be exceptionally useful in the field of Web services, where that's exactly what gets sent and received: XML messages. In this tip, I'll look at how to use an XForms browser as a Web services client, sending a SOAP request and displaying the results directly in the browser."

Posted by roadnick at 08:02 PM | Comments () | TrackBack

June 22, 2004

Saving tadpoles

I know that I work too much, but what bothers me isn't so much how much I do as what I don't get to do. Like saving tadpoles.

My pool pump hasn't worked for about 2 years, but now I'm resigned to get the pool swimmable. (The fact that's it's been 90 degrees for days may have something to do with it.) Thing is, if you put a large body of water out there and just, well, leave it, the frogs WILL find it. And they'll ... do what frogs do.

So now I have a pool filled with thousands of tadpoles in various states of development, which made me feel really bad when I decided to drain the pool to get it ready.

Fortunately, Cheyenne and Dakota are here, so now that the pool's down to about 4 inches, they're in there gathering up tadpoles. And let me tell you, tearing myself away wasn't easy. It's a simple pleasure, laughing while the tadpoles tickle your feet, gathering them up and putting them into a container. I miss that kind of thing.

That's the answer, really. What do I want to do with my life? I want to have time to gather tadpoles.

Posted by roadnick at 12:43 PM | Comments () | TrackBack

June 21, 2004

Don't worry, it's only "information extraction"

I can't even comment on this analysis of the legal twisting and turning of reality with regard to the torture of Iraqi (and Afgani) prisoners. Consider the notion that:

In order to prove 'severe mental pain or suffering,' the statute requires proof of 'prolonged mental harm' that was caused by or resulted from one of four enumerated acts... [T]he development of a mental disorder such as posttraumatic stress disorder, which can last months or even years, or even chronic depression... might satisfy the prolonged harm requirement... [I]f a defendant [interrogator] has a good faith belief that his actions will not result in prolonged mental harm, he lacks the mental state necessary for his actions to constitute torture. A defendant could show that he acted in good faith by taking such steps as surveying professional literature, consulting with experts, or reviewing evidence gained from past experience... Because the presence of good faith would negate the specific intent element of torture, good faith may be a complete defense to such a charge.

It makes me physically ill.

Posted by roadnick at 12:50 PM | Comments () | TrackBack

June 20, 2004

Chronic Fatigue, Fibromyalgia related to a bacteria

People with Chronic Fatigue or Fibromyalgia are often looked at as "faking it" or that it's "all in their head" but these two diseases are apparently related to a verifyable bacteria that can be treated with antibiotics. I personally have never claimed either nor considered myself disabled, but I do have lots of pain most of the time, as well as a bad stomach and other issues. (The fatigue I can easily explain, given my schedule.)

So I was particularly interested in this report that these two diseases (and Gulf War syndrome) have been linked to a particular set of bacteria, and have been successfully treated with antibiotics.

We have been conducting research on mycoplasmal respiratory infections that cause a flu-like illness that results in systemic CFS and/or FMS. Earlier we conducted a pilot study of Desert Storm veterans and their families. This very preliminary study showed that 55/73 GWI patients, including symptomatic family members, responded to an anitibiotic (doxycycline) that is effective against a variety of mycoplasmas, and most of the soldiers and their symptomatic family members eventually recovered from their illness (4). Since this study we have continued to gather evidence that mycoplasmal infections, and probably other chronic infectious agents, are causing the chronic signs and symptoms that are similar to CFS/FMS in approximately one half of GWI cases, and these illnesses can be successfully treated with antibiotics (5,6). As GWI progresses, there are a number of accompanying problems, including MS-like, ALS-like and Arthritis like signs/symptoms, and this is also consistent with mycoplasmal infections that penetrate into nerve cells, synovial cells, etc.
Posted by roadnick at 11:57 AM | Comments () | TrackBack

June 19, 2004

Posting a book that's "in progress"

For a while now, I've been thinking about the idea of posting chapters of a book as I write them and inviting comment. I've been particularly thinking about it lately, as I ponder a book that's more ... well ... philosophical than my usual work. (More on that when I've figured out how to express it in words rather than just vague notions and gestures.) Anyway, I must have been thinking too loudly, because today's San Jose Mercury News talks about what happens when authors open texts online for others to edit.

I do think it's going to happen more and more often, as we fully acclimate to "social media".

Posted by roadnick at 10:42 PM | Comments () | TrackBack

eBaum's World

I don't know if I'd agree that eBaum's World is "so funny you won't be able to sleep at night" but it sure is great. The site hosts "Funny movies, flash cartoons, funny pictures, magic, prank phone calls, flash games, and tons more!" But just the optical illusion on the home page tells you this is something different. Cool stuff.

Posted by roadnick at 07:33 PM | Comments () | TrackBack

June 17, 2004

Using the Generic Log Adapter with the Log and Trace Analyzer

Now featured on developerWorks: Using the Generic Log Adapter with the Log and Trace Analyzer

The GLA and LTA are Eclipse-based tools that enable logs to be parsed for occurrences of pre-defined events, relate those events to situations, and recommend actions based on information in a knowledge base. This tutorial is of particular interest to developers and administrators of applications with dependencies on multiple servers, such as DB2, Apache, and WebSphere. The key lesson imparted here is how to use the GLA to create your own adapter for custom application logs. Additionally, the tutorial introduces the underlying elements of the log adapter process. These low-level enablers of autonomic computing systems are an important contributor to the creation of more autonomic computing systems. This tutorial takes you through an example of how high-level open standards, such as the Common Base Event description, can be incorporated into development and administration functions at a practical level.
Posted by roadnick at 11:50 AM | Comments () | TrackBack

June 16, 2004

Checkboxes and missing values

Hi

Just read your article on php and forms. Thanks for putting such a resource on the web. Just one quick question though. I don't want to have a check box initially checked but when I leave it blank it doesn't show up in the results. I am trying to produce a csv so this leaves me with one less coloum.

Is there a way around this

Thanks
David


Hi, David!

The nature of checkboxes is that they only show up if they're selected. You can either use a radio button instead, or you can stay with the checkbox but also include an empty hidden field of the same name. That way there's always a "value" with that name, even if the checkbox doesn't come through. Be careful, though, you'll then have to deal with multiple values for a
single field.

I hope that helps!

---- Nick

Posted by roadnick at 12:46 PM | Comments () | TrackBack

June 15, 2004

Fantastic music, and lots of it

I love to listen to soundtracks, particularly when I'm writing, but I have a limited collection to listen to. (Still trying to scrape together the money for Pirates of the Caribbean. Definitely a winner!) Now I've discovered StreamingSoundtracks.com and I am in musical heaven. The site has hundreds of soundtracks available to listen to, but what's cool is that you can request a particular track, and it gets queued. You can see what's in the queue, and you can see how long each piece lasts, and how much time is left on the current track. What's also nice is that tracks can't be requested more than once every five days, so you don't hear the same tracks over and over again.

I'm hooked!

Posted by roadnick at 05:34 PM | Comments () | TrackBack

81% is a "blackout"?

It's interesting that we consider an 81% response rate to the top 40 major sites -- such as Yahoo, Google, Microsoft.com, and Apple.com -- to be a blackout of major Web sites. I don't know that I'd agree, but how integrated are we that we even notice this kind of thing?

Posted by roadnick at 05:20 PM | Comments () | TrackBack

Know your path

Here's a little tidbit for you: always make sure you know what application you're executing. Three times now, the http://www.metrosphere.com has gone down because the HTTP server hung up. That sounds like a simple problem, except that MetroSphere runs on IBM's WebSphere Portal, so the HTTP server is only a small part of the process. Trouble was, when I restarted the httpd server, it wasn't recognizing the portal application server. Twice, I spent a week in technical support hell, with a severity one problem (production system down). That means I personally have to be on call 24 hours a day until it's resolved.

Twice now, the problem has mysteriously resolved itself after we figured out all the other problems. This time I decided to take the bull by the horns, so to speak, and find out what the deal was with the HTTP server before I even touched the application server.

The answer?

Although I was going to the /opt/IBMHTTPServer/bin directory,

httpd

was running a different application than

./httpd

The former was running an HTTP server that is, I think, part of Linux. The latter actually runs the version we need to run.

Let that be a lesson to you. (I know it's a lesson to me!)

Posted by roadnick at 12:57 PM | Comments () | TrackBack

June 12, 2004

Mediocrity as a way of longevity

Now here's an interesting piece of analysis. Garfield has been around since 1978, and we don't hate him yet. But nobody's ever going to call cartoonist Jim Davis a genious -- unless they understand marketing. In Garfield - Why we hate the Mouse but not the cartoon copycat we see that the lasagna-loving cat was specifically designed as a marketing machine, and man, has it worked. But the most interesting part is that part of the formula for success lies in not being greedy. Davis understands that if Garfield gets too popular, he'll be easy to hate; his popularity depends on his inoffensiveness.

In the late 1980s, Garfield plush toys with suction-cup feet were so popular than criminals broke into cars to steal them and sell them on the black market. Davis, protective of his creation's unobjectionable blandness, knew he had to act fast before people began to hate Garfield. "We accepted the royalty checks, but my biggest fear was overexposure," he told Entertainment Weekly in 1998. "We pulled all plush dolls off the shelves for five years."
Posted by roadnick at 05:28 PM | Comments () | TrackBack

How green was the Gipper?

Oh, and I forgot about Reagan's environmental record.

Posted by roadnick at 12:51 PM | Comments () | TrackBack

June 11, 2004

Um, this is Ronald Wilson Reagan, right?

I've been listening to the supposedly liberal press falling all over themselves to appear conservative for a whole week now, I have to ask: we are talking about Ronald Reagan, right? President of the United States between 1980 and 1988, right? That Reagan? 'Cause you'd be hard pressed to know it watching the obsequeous coverage on all the networks this week. Maybe the media is the one suffering from Alzheimers. I mean, we keep hearing about "the Great Communicator" and how he was so "idealistic" and stuck to his principles and all that. I've heard him described as "the Republican party's JFK." So tell me, why aren't we being reminded of:

  • Huge tax cuts for the rich
  • Huge tax increases for the working class
  • Firing the Air Traffic Controllers
  • Vigorously opposing (to the point of veto) unemployment insurance for farm workser
  • Ketchup as a vegetable
  • Cutting the budget of the Department of Housing and Urban Development by 70%
  • Rolling back tax incentives for low-income housing
  • Reaganville
  • Dismantling the California mental health system
  • Cutting state funding for mental hospitals and putting their patients on the streets
  • Support for the Apartheid government in South Africa
  • Iran-Contra
  • El Salvador

What else did I miss?

Posted by roadnick at 08:50 PM | Comments () | TrackBack

June 09, 2004

Now THAT was a war

With all of this talk about Iraq, it's interesting to go back and listen to the real radio broadcasts of World War II. And I'm not just talking about broadcasts you've heard a gazillion times in retrospectives. I'm talking about weekly "world news updates" -- sponsored by Admiral radios, which regrets that because of defense orders, they can't make consumer radios until the war is won, but see your Admiral dealer to keep your radio in tip-top shape for the duration, no matter what brand it is -- in addition to British news, and perhaps the most interesting, English-language German propoganda broadcasts.

But what's really interesting to me is the scale of things. We have, what 125,000 troops in Iraq? The D-Day invasion involved 4 and a half MILLION allied troops. The war touched every part of American life, right on down to (unless I didn't hear it correctly) the edict that all able-bodied men between 20 and 45 were to receive military training. And factories taken over by the defense department because they weren't producing material fast enough.

The complete broadcast is 60 hours, and covers the whole war chronologically. I recommend trying to catch the early war, when the Axis was winning. It's quite a perspective changer. Especially the Germans saying that the fact that they were so technologically advanced that they conquered France in 6 weeks should tell the British they couldn't possibly stand up to Germany. And we all know how that ended.

Interesting lessons history teaches, if we pay attention.

Posted by roadnick at 02:02 AM | Comments () | TrackBack

June 03, 2004

Michael Moore Hates America

This is cool. Michael Moore Hates America is not meant as a hatchet job of the "documentary" filmmaker, but almost as a rebuttal of his "America is awful" philosophy. In a bizarre-ly Roger and Me-like way, Michael Wilson tries to get an interview with Moore, and also looks at how the little guy can still make it in this country. But along the way, he looks at the documentary process, and from the trailer, that looks fascinating. But then, I've always been a documentary junkie.

Posted by roadnick at 12:32 PM | Comments () | TrackBack

June 02, 2004

Understand the Autonomic Management Engine

Now on developerWorks: Understand the Autonomic Management Engine

"The idea of an autonomic computing system is attractive -- who wouldn't want a system that knows what to look for, and what to do if it finds it? But, building one from scratch is too much of an undertaking for most shops. Fortunately, the Autonomic Management Engine simplifies the process. This tutorial explains how AME works and shows you how to embed it into one of your own applications."

This is actually pretty cool. Well, I think so, anyway. :)

Posted by roadnick at 11:34 AM | Comments () | TrackBack