Yeaaah Spring Break

I'll be in Tennessee/North Carolina Smoky Mountains National Park for a week. So I won't be commenting.

On a different note, my interview with CTY went well. I screwed up on one or two questions, but I really got the interviewer's interest with my lesson plan. Hopefully I'll get the job *crosses fingers*

I'll also be kind of awkward if she finds this post. Oh well.
No comments

So Long and Thanks for All the Fish

And I'm done with my dolphin project.

Phew.
No comments

St. Patty's Day

I was walking home this morning at 5-ish, after finishing a philosophy paper. Some middle aged guy biked past me in the opposite direction. He said, "had a little too much to drink for St. Patty's Day huh."

Yeah. Definitely.
No comments

Widgets

I'm probably not as busy as I claim (or think) I am.

A quick search for my username came up with this:

http://www.widgetbeat.net/index.php/02/2008/notes-list-todo-widget-review/

Cool.
No comments

Hiatus

Due the the amount of work, I will be taking a brief hiatus from blogging for the next two weeks or so, save for the weekly updates on Sunday.

I look forward to when I'll have the time to write again.
No comments

Week of 2008-03-03

Busy week. Went climbing Monday, then class, GSW, and meeting. Had a better Tuesday than the last, with my project closer to completion. Another meeting at night. Spring break planning is going well, although a potential kink just came up. Starting Thursday night I didn't sleep till 3 (and on Sunday morning, 5) in the morning, working on a GUI regex webpage. It works pretty well; I'm more than pleasantly surprised by how good it looks. That's really it... two weeks more of work hell, and then I'm free! Free! For a week. Bummer.
No comments

AJAX Upload (Of Sorts)

I've said before that I'm working on a project to put a graphical front end to regular expressions. One feature we put in (among the plethora which are not really necessary) is the ability to upload a text file from your computer, and play with regex on it.

Despite all the tutorials out there, it turns out that getting a callback function from upload is really really easy. Since my method is the simplest I've seen (and I've seen quite a few while trying to figure out how to do it), I thought I would share.

Here's the html:

<iframe style="" id="TARGET_IFRAME_ID" onLoad="CALLBACK_FUNCTION();"></iframe>
<form action="server_upload_script.php" method="post" enctype="multipart/form-data" onSubmit="this.target='TARGET_IFRAME_ID';">
  <input name="max_file_size" value="100000" type="hidden">
  <input name="FILE_IDENTIFIER" id="input_file" type="file">
  <input value="Upload File" type="submit">
</form>

That's it! All uppercase variables should match, through all code in this post. The max_file_size above is not really necessary, as it is easily overridden (or so I read). When the user clicks submit, the iframe (as the target of the form) will reload with the output of server_upload_script.php. For my purposes, I just need to echo to file, so my php script is simple:

<?php
$tmp_file = "tmp.txt";
if (move_uploaded_file($_FILES['FILE_IDENTIFIER']['tmp_name'], $tmp_file)) {
  $file_handler = fopen($tmp_file, 'r');
  $contents = fread($file_handler, filesize($tmp_file));
  fclose($file_handler);
  unlink($tmp_file);
  echo $contents;
} else{
  echo "There was an error uploading the file, please try again!";
}
?>

This will save the file to a temporary tmp.txt (creative naming, I know), then open the file and read it back. If there's an error with writing the file, an error message will appear instead of the file. This could be ignored, but works well for our purposes since it shows up on a text area anyway.

Finally, now the iframe has the file you need, the last thing is to use javascript to do whatever you want with that data. That's below:

function CALLBACK_FUNCTION() {
  var file = document.getElementById(TARGET_IFRAME_ID).contentDocument.body.innerHTML;
  if (file !== '') {
    /*
     * DO OTHER STUFF
     */
  }
}

And that's it! Three short sections of code to get an upload, not that bad.

The funny thing about this is that I spent 2 hours just to come up with this. And when I started, I didn't even know a input element can take type="file"
No comments