My goals for 2011

2011 is going to be a great year, I can feel it. Following up my last post, here are some of the things that I’m planning on accomplishing.

  1. Speak at more tech conferences and user groups
  2. Travel more, possible out of the country
  3. Rehab my leg back to 100% strength
  4. Work out more, get into awesome shape
  5. Develop more iPhone apps
  6. Get an android phone to test / develop with
  7. Do more community service
  8. Pay off more of my debt
  9. Automate more of my income
  10. Get more tattoos

My goals for 2010, In Review

I started 2010 off with a list of things I wanted to accomplish. Since the end of the year is just hours away, I figure it would be fun to revisit the goals I had set out for myself.

  • Create a few more iPhone apps

In 2010, I launched 3 new iPhone apps, and I have one pending approval, for a total of 4 apps in 2010. I also started a consulting company, NewLeaf Labs, that specializes in iPhone app development. In January 2010 taught an iOS development at a college in San Bernardino California. I guess you can say that 2010 was packed full of iPhone, and I met my goal. 

  • Train more / get back into fighting condition

On January 28 2010, I destroyed my ACL in my left knee and had to have major knee surgery. Of course I blogged about it. Recover from the surgery has been a longer road then expected. It’s been 11 months since my injury. I’ve been going to physical therapy 3 days a week and lifting weights when I can. I still have a long way to go to be 100% again, but I can honestly say that having my mobility taken away has made me appreciate my body, and fitness even more. 2011 will be my year of body building.

  • Switch over to Mac completely

For the most part I would say that I reached this goal. At home I use my Mac Book Pro 95% of the time. My PC is mostly for media sharing via my XBox. I love the stability of the Mac.

  • Launch “IE Tech Scene”

Yeah, this one is a big #FAIL. Not being able to drive a car or stand for 6 months really put a damper on this one. Maybe 2011 will be more fruitful in this are.

  • Automate more of my income

I’m a huge fan of The 4-hour Work Week, but I’ve back slid on this one. I sold the pomade company I had and took 2010 off. I already have plans for 2011, and I have people in the US, India and China working with me to get the new project off the ground. More details to come… 🙂

  • Blog more

Maybe I didn’t do the best job on this one. Looking at my stats on this blog, I only made 4 more posts in 2010 (44 posts) then I did in 2009 (40 posts). However, I did start a new blog, www.IAmStraightEdge.com, and I have made a ton of posts over there. I’m going to give myself the win.

  • Reduce clutter in my life

This is an on going battle. I will say that my office is the leanest it has ever been and I can park 2 cars in my garage. I’ll count this as a win, but i still have so much more to organize / throw out.

  • Attend more conferences / conventions

This one gets a big win. I was unable to walk for 6 months this year, but I still managed to make it to 3 conferences, WordCamp LA, CFUnited, and BlogWorld Expo. I was a speaker at WordCamp, and CFUnited. I hope to speak at more conferences in 2011, including Blog World Expo.

  • Take more trips / vacations

I thing this goal can be checked off the list as well. Again, for not being able to walk for 6 months, I was able to spend 2 weeks in Portland, a canoe trip in Minnesota, a 5 days in LasVegas, and a week in the Washington DC area.

  • Be as wireless as possible

2010 was the year of the Bluetooth. Bluetooth mouse, and Bluetooth Headphone. Check.

  • Get a few more tattoos

Yeah, this didn’t happen. I didn’t get a single tattoo in 2010. Weird (for me at least)

  • Continue to be healthy and not get sick

Well, being injured technically isn’t sick, but I’m going to fail myself on this one. Not being able to walk for 6 months doesn’t exactly fall into the “healthy living” section of life.

  • Pay off my credit cards

Massive medical bills from surgery, doctors appointments and physical therapy have made it tough to do. I’m hoping that 2011 will really be the year that I can declare that I am debt free. It’s a good goal for all of us to have.

Using cURL and PHP to upload files through a form post

Lately I have been working on a project that requires me to use PHP to interact with a REST based service. cURL is the logical choice for making HTTP calls to the REST service.

I love cURL, I’ve blogged about it before, but I recently ran into some major issues.

The REST service I was using required me to send two files along with some meta information. easy enough. I used the following code:

$postFields = array();

//files
$postFields['file'] = "@$filePath";
$postFields['thumbnail'] = "@$thumbnailPath";

//metaData
$postFields['title'] = "$title";
$postFields['description'] = "$description";
$postFields['tags'] = "$tags";
$postFields['licenseinfo'] = "$licenseinfo";
$postFields['token'] = "$userToken";

$curl_handle = curl_init();

curl_setopt($curl_handle, CURLOPT_URL, $api_url);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_POST, true);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $http_post_fields);

//execute the API Call
$returned_data = curl_exec($curl_handle);

The code worked great, sending an “at” sign (@) before the file path makes sure that cURL sends the file as part of a “multipart/form-data” post. Exactly what we needed.

The form post from cURL worked great, but the REST service was retuning a 400 error and saying “The specified thumbnail file is not supported.”. I was at a loss. The service documentation stated the “jpg, jpeg, gif, and png” files were supported.

I ended up contacting the developers of the service who told me that the content type for the file had to be set to “image/jpg” (for jpg).

After pouring through the cURL documentation and not finding anything about how to set the content type for a single file in a “multipart/form-data” post, I turned to Goolge. My searches with about as helpful as the cURL docs. I sent a few hours hacking my code and trying some things, I ever read some posts from 2008 saying that is was not possible to do. Then, I got a break through, a single ray of light. On a message board was a single sentence replay. “You should try this… $image;type=image/jpg”.

That was the break through I needed. Below is final updated code:

$postFields = array(); 

//files
 $postFields['file'] = "@$filePath";

//get the extension of the image file
$tumbnailExtention = preg_replace('/^.*\.([^.]+)$/D', '$1', $thumbnailPath);
$postFields['thumbnail'] = "@$thumbnailPath;type=image/$tumbnailExtention";

//metaData
$postFields['title'] = "$title";
$postFields['description'] = "$description";
$postFields['tags'] = "$tags";
$postFields['licenseinfo'] = "$licenseinfo";
$postFields['token'] = "$userToken"; 

$curl_handle = curl_init();

curl_setopt($curl_handle, CURLOPT_URL, $api_url);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_POST, true);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $http_post_fields); 

//execute the API Call
$returned_data = curl_exec($curl_handle);

In summary, if you need to set the content type of a file being sent an image through cURL, via a POST, use the following format:
$postFields[‘file’] = “@PATHTOFILE;type=CONTENTTYPEHERE”;