Access your email marketing account.
Username: Password:

Blue Ember Design

Web Design Blog

Sharing thoughts, opinions, and strategies for building an effective web presence and a profitable online marketing campaign.

CodeIgniter File Upload: Changing the File Name

Topic: CodeIgniter

Update: As of version 1.7.2, CodeIgniter now has a built-in option to specify the uploaded file name. Placed in the $config array, ‘file_name’ sets the desired end name and should be provided without an extension. The extension will be carried across from the original file.

——

There has been some interest lately on our blog about how to change the file name of uploaded files with CodeIgniter. We will review how to do this with the base File Upload library as well as extending the library to allow for a defined file name.

Using the Base File Upload Library

The base file upload library has a built-in option to “encrypt” the file name for a freshly uploaded file. According to the documentation, that option is ‘encrypt_name’ and takes a Boolean value. If set to TRUE, the file name is renamed by running it through this set of functions:

$filename = md5(uniqid(mt_rand())).$this->file_ext;

This essentially generates a nice random MD5 hash that will likely not collide with other files in your directory. Most of the time this method for renaming will work just fine, but what if we want to specify the name rather than have it random?

Extending the File Upload Library

This method involves extending the base library which we have done before for other file upload customizations. In this method, the do_upload() function accepts a file name and applies it to the file. Here is the code used to accomplish that outcome:

<?php
 
function do_upload($field = 'userfile', $new_name='') {
 
    if ( ! isset($_FILES[$field])) {
      $this->set_error('upload_no_file_selected');
      return FALSE;
    }
 
    if ( ! $this->validate_upload_path()) {
      return FALSE;
    }
 
    if ( ! is_uploaded_file($_FILES[$field]['tmp_name'])) {
      $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error'];
 
      switch($error) {
        case 1: // UPLOAD_ERR_INI_SIZE
          $this->set_error('upload_file_exceeds_limit');
          break;
        case 2: // UPLOAD_ERR_FORM_SIZE
          $this->set_error('upload_file_exceeds_form_limit');
          break;
        case 3: // UPLOAD_ERR_PARTIAL
           $this->set_error('upload_file_partial');
          break;
        case 4: // UPLOAD_ERR_NO_FILE
           $this->set_error('upload_no_file_selected');
          break;
        case 6: // UPLOAD_ERR_NO_TMP_DIR
          $this->set_error('upload_no_temp_directory');
          break;
        case 7: // UPLOAD_ERR_CANT_WRITE
          $this->set_error('upload_unable_to_write_file');
          break;
        case 8: // UPLOAD_ERR_EXTENSION
          $this->set_error('upload_stopped_by_extension');
          break;
        default :
          $this->set_error('upload_no_file_selected');
          break;
      }
 
      return FALSE;
    }
 
    $this->file_temp = $_FILES[$field]['tmp_name'];
    $this->file_size = $_FILES[$field]['size'];
    $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']);
    $this->file_type = strtolower($this->file_type);
    $this->file_ext  = $this->get_extension($_FILES[$field]['name']);
 
    // check if a name has been specified, if so set it
    if ($new_name != '') {
      $this->file_name = $this->_prep_filename($new_name . $this->file_ext);
    }
    else {
      $this->file_name = $this->_prep_filename($_FILES[$field]['name']);
    }
 
    if ($this->file_size > 0) {
      $this->file_size = round($this->file_size/1024, 2);
    }
 
    if ( ! $this->is_allowed_filetype()) {
      $this->set_error('upload_invalid_filetype');
      return FALSE;
    }
 
    if ( ! $this->is_allowed_filesize()) {
      $this->set_error('upload_invalid_filesize');
      return FALSE;
    }
 
    if ( ! $this->is_allowed_dimensions()) {
      $this->set_error('upload_invalid_dimensions');
      return FALSE;
    }
 
    $this->file_name = $this->clean_file_name($this->file_name);
 
    if ($this->max_filename > 0) {
      $this->file_name = $this->limit_filename_length($this->file_name, $this->max_filename);
    }
 
    if ($this->remove_spaces == TRUE) {
      $this->file_name = preg_replace("/\s+/", "_", $this->file_name);
    }
 
    $this->orig_name = $this->file_name;
 
    if ($this->overwrite == FALSE) {
      $this->file_name = $this->set_filename($this->upload_path, $this->file_name);
 
      if ($this->file_name === FALSE)
      {
        return FALSE;
      }
    }
 
    if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name)) {
      if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name))
      {
         $this->set_error('upload_destination_error');
         return FALSE;
      }
    }
 
    if ($this->xss_clean == TRUE) {
      $this->do_xss_clean();
    }
 
    $this->set_image_properties($this->upload_path.$this->file_name);
 
    return TRUE;
  }
 
}
 
?>

Much of this code is taken from the existing File Upload library, but is provided above for the sake of completeness. Comments have been removed to shorten it up a bit, but can be found in the original Upload.php for further understanding.

The file name can be set in the controller by calling the do_upload() function as follows:

$this->upload->do_upload('form_field_name', 'new_file_name');

With this extended File Upload library, the following circumstances exist:

  1. The file name provided in do_upload() should not have an extension. The extension from the original file will be applied.
  2. If ‘encrypt_name’ is set in $config, it will take precedence over the specified file name.

Have any other tips for changing the file name for uploaded files in CodeIgniter? Share it in the comments!

Announcing the CodeIgniter Dreamhost API Library

Topic: CodeIgniter

As we’ve said many times before, we are avid CodeIgniter developers at Blue Ember Design.  The framework is fluid and light-weight and the developer community is great.

We’ve been inspired many times by the extensive list of CodeIgniter libraries provided by Elliot Haughin and decided we ought to follow in his footsteps with a great new API library.

Today we are announcing the release of a Dreamhost API library for CodeIgniter.  The API lets you integrate common Dreamhost Panel activities into your web applications.  With this library, you can integrate tasks like announcement list management and Dreamhost PS resizing right into your CodeIgniter applications.  Pretty great!

We’d love to hear feedback about the library, how you are using it, and if you have any suggestions.  Enjoy!

Get the CodeIgniter Dreamhost API Library Here

poMMo: Open Source Email Marketing Software


Update: We have been using poMMo for a solid month now with one of our clients and unfortunately we can no longer recommend it as a high-quality piece of email marketing software.  It appears to have been out of active development for some time (Latest release was Apr 03 2008) and while there is a community around poMMo, it’s limited in its ability to support issues.

——

While Blue Ember Design does offer its own email marketing solution, we occasionally have some smaller clients that want to use self-hosted email marketing software.  Although not typically advisable, we do allow it for some clients with small subscriber lists (the idea being that it will get them started and they can move over later).

Up until last week, we really were pretty disappointed with many of the open source email marketing software options.  In the past we have implemented  GNU Mailman as well as PHPMailer-ML for our clients, but each of these has their major downfalls.  Mailman just feels way too bulky, takes too much hand editing for configuration, and is a beast for client training.  PHPMailer-ML was simple to configure, but had a pretty clunky interface.  We also ran into some issues with the database connection being dropped while sending leaving us no clue where it left off.  So the search for a great free email marketing solution continued.  Enter poMMo.

pommo-dashboard

poMMo is very easy to configure and has a decent looking, easy-to-use interface.  There is one configuration file that really only required MySQL database connection information and the system is off and running.  It self-installs and does it in a way that it could be run “out-of the box”.  Of course we do customize the HTML emails for our customers, but that was just as easy with its email template feature.

Here are some of the features we like about poMMo:

  • Email throttling (by total emails sent and by destination domain)
  • Auto generated HTML subscription forms
  • Custom field collection (First Name, Last Name, City, State, etc.)
  • Groups for mailing a subset of the full subscriber list
  • HTML and Text-Only email options
  • Email history stored as HTML pages for archiving.  This is great for mail reader issues with HTML.

pommo-compose

Known Issues and Desired Features

  • There is an issue with the admin interface in Firefox where the body of the content falls below the sidebar.  This is just a small CSS issue that can be fixed with some slight tweaking.
  • The system is set up to have an email address that receives bounces, but there is no automated bounce processor.  It would be nice if it could automatically unsubscribe invalid addresses after a set number of bounces.
  • When composing emails, poMMo uses FCKeditor to allow for advance editing.  The software doesn’t display the ‘Source’ button to view the email as HTML.  This would be nice for advanced users that want to hand manipulate their email’s HTML.  Just a small hang up =)

25 Comments

5 Ways to Jumpstart Your Company’s Branding and Identity


All successful companies (in part) thrive because of their corporate identity.  Here are 5 tips for building a powerful brand and using it to drive business choices, increase sales, and manage a corporate image in the eye of the public.

What is a “Brand”?

A brand or corporate identity is simply how others view a company from the outside.  The term can be somewhat diluted by the way it is used in every day conversation (“What brand of ketchup did you get?”), but at its core it is much more powerful.  A brand should be memorable, targeted, and consistent in order to be effective.

Is Your Branding Memorable?

One key to branding success is creating a corporate image that people will remember. There are logos in the business world that are timeless and can be recognized from a mile away.

corporate-logos

A brand should have impact on its viewer and should be something that when it comes time to buy they can’t help but think about your logo, your products, and the way they will feel once they own your goods.

Does Your Brand Effectively Address Your Target Customer?

Think about the brands in front of your eyes every day. Does their logo, printed material, website, and product cater to the audience to which they are marketing? Are they either telling you that you are their customer OR making you wish you were? If so, this is the sign of great brand development. Here are a couple examples of companies that perfectly hit their target market:

  • mercedesMercedes-Benz – What do you think of when you picture a Mercedes-Benz? You probably think of wealth, upper class, celebrity…to name a few.  This is a corporate identity built right.  To build this image, Mercedes creates high-quality vehicles and markets to high net worth customers.  You won’t see a TV ad spot of a Mercedes car salesman yelling out about record low prices.  Rather, their ads show cars racing around curves or the vehicle parked in front of the driver’s 4,000 sq ft vacation home.  This campaign conveys a sense of wealth and therefore establishes their brand in that same way.
  • Apple Computers – Steve Jobs is a branding genius.  Period.  Everything about Apple is consistent with their desired image.  MacBooks are for artists, creatives, designers…or so Apple wants you to believe.  Is it really true that you can’t edit a video on a PC?  Hardly the truth.  Through numerous branded ad campaigns, Apple uses music, stunning aesthetic, and product differentiation (Windows vs. Mac) to portray their hip, designer-friendly identity.  Check out the Windows vs. Mac video below if you haven’t seen it on TV.
  • gatorade with michael jordanGatorade – Much like the brands above, Gatorade does a great job at setting their branding for their target market.   Gatorade is for the true athlete!  They convey this image to their customers with ad campaigns that show our favorite celebrity athletes chugging a Gatorade after a big game or having them sweat it from their pours like Gatorade and their success go hand-in-hand.  Clearly, the key to success as an athlete is practice and natural skill, but Gatorade has us thinking they are the critical third part of the formula to success.  This is great brand development.

Do Your Products/Services Match The Identity You’ve Created?

A company can spend years building the perfect identity, but if the product or service behind the brand doesn’t match it will be all for nothing.  Would you expect to see Taco Bell marketing itself as an authentic Mexican restaurant? How about the corner liquor store building a brand around rare fine wines when their best bottle is a “Two Buck Chuck“? If the product doesn’t match the brand your customers will figure it out quickly.  It’s OK to build a brand around being cheap (look at the Dollar Tree), but everything has to be consistent with the image you set.   That leads to our next point on consistency…

Is Your Branding Consistent?

Not only does the product need to fit into the brand, the brand needs to be consistent throughout.  For this reason, companies that are serious about their identity create style guides to ensure that consistency is always a priority.  Everything from business cards and flyers to the website and email campaigns are all held to the same design style guide.  By following the guide, the company becomes the brand rather than it just being something that the company does.  Straying away from the brand can potentially mean losing control of how your company is viewed by the public.

Are You Committed To Building Your Brand?

Building a successful brand isn’t easy.  It will take time and dedication to “massage” your company’s identity into what you want it to ultimately become.  By following the few tips above and being diligent about the design of marketing materials, the message you convey, and the products or services you offer, you will come out the other end with a quality brand that is sure to earn respect and boost sales from your target market.

What other strategies have you used to build your desired corporate identity?

1 Comment

Common Issues with CodeIgniter File Upload

Topic: CodeIgniter

Last post we wrote about how to extend the File Upload Library to set disallowed file types rather than only the allowed file types. We saw a fair amount of interest in file upload for CodeIgniter and have decided to post some tips for troubleshooting the most common issues we’ve come across.

“The filetype you are attempting to upload is not allowed”

Many times this is the appropriate error you would expect to see after a disallowed file type has been uploaded, however, we have noticed that there are a couple cases where files inaccurate fail.  Here are some potential issues and their solutions.

  • Option ‘allowed_types’ Is Required
    If no list of file types is provided in $config['allowed_types'], you will always get this error. The documentation shows the options with a default value of “none”, but it fails to make it obvious that it is a required input.
  • MIME Type Is Not Listed
    Another potential solution to this problem could be that the extension is not listed in config/mime.php. Any file type that should be allowed must exist in the $mime array or it will fail.
  • MIME Type Variations
    Different browsers often return different MIME types. For this reason, config/mimes.php accepts multiple MIME types for a given file type. Many times a variant of the main MIME type will need to be added to accommodate all browsers.

$data['file_path'] is an Absolute Path

The $config array accepts ‘file_path’ as either a relative or absolute path. It is definitely convenient to allow either as an input, however, the $data array returned after processing the file returns an absolute path. This can certainly cause some issues if the expectation is that the returned ‘file_path’ is in the same format as the ‘file_path’ provided in the $config array.

Accepting Multiple Files in a Form

There is an ongoing discussion with code segments in the CodeIgniter Forums on how to accept multi-file uploads.  There are a handful of great solutions available and lots of people supporting the topic.

What other issues have you come across with the File Upload Class in CodeIgniter?  How do you see it being able to be improved or extended to be the most useful?

5 Comments

Client Testimonial

"Blue Ember Design orchestrated and implemented the successful redesign, rebranding and rebuilding of our real estate website. Our vision for the website was respected, embraced and improved upon. Our clients have responded well to the new site and our business has been turbo boosted."

Shiloh Hagen

The Cox Team

Subscribe

Stay up-to-date with our latest postings without having to check the site.