Upload with Uploadify running in public_html folder

Just to try it out I tried to get Uploadify to work in my public_html folder. I set it up according to the guidelines in the docs/example and ran. It returned success but the file wasn’t uploaded.

My first debug idea was to add an alert to the onError event. It wasn’t triggered.

My second idea was to try and print the response in the onComplete event. I added:

'onComplete': function(event, queueID, fileObj, response, data) {
    alert('onComplete: ' + response)
}

and it returned:

Warning: move_uploaded_file(/var/www/home/ola/public_html/uploadify/uploads-folder/test-image.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/ola/public_html/uploadify/_lib/uploadify.php on line 40

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php1rJUsg' to '/var/www/home/ola/public_html/uploadify/uploads-folder/test-image.jpg' in /home/ola/public_html/uploadify/_lib/uploadify.php on line 40

I guess it’s some rewrite issues when Apache rewrites the /home/ola/public_html folder to /~ola.

I opened uploadify.php (the ”server side code” for Uploadify) and replaced:

$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';

with:

$targetPath = $_REQUEST['folder'] . '/';

And it worked.

Fix for WordPress, AutoFocus and wide images problem

Update: I uploaded my version of AutoFocus to Google Code.

I’m building a photo blog to show mostly panoramas using WordPress with the AutoFocus plugin. It works fine but I had one issue.

My panoramas are often in 8:1 (width-height) proportions. When I scale the images it means that I get images that are about 100 px high at 800 px width. It makes the images wrap around the div on the first page in the AutoFocus theme.

Wordpress-AutoFocus-Issue

To fix it I installed the Additional image sizes plugin.

Wordpress-AdditionalImageSizes

I configured it to make 800 x 300 images with cropping. I called them 800x300Crop.

Then I added three lines to the function the_post_image_url($size=large) in the functions.php file in AutoFocus. See the code on Google Code.

// Post Attachment image function. Image URL for CSS Background.
function the_post_image_url($size=large) {

        global $post;
        $linkedimgurl = get_post_meta ($post->ID, 'image_url', true);

        if ( $images = get_children(array(
                'post_parent' => get_the_ID(),
                'post_type' => 'attachment',
                'numberposts' => 1,
                'post_mime_type' => 'image',)))
        {
                foreach( $images as $image ) {
                        $attachmenturl=wp_get_attachment_image_src($image->ID, $size);

                        // Added for panoramas
                        // Use the Additional image sizes plugin to generate images that
                        // are 800 x 300 px (cropped) that can be used if the original image
                        // isn't big enough (width or height) when downscaled
                        if($attachmenturl[2] < 300 || $attachmenturl[1] < 800) {
                                the_post_image_url("800x300Crop");
                                return;
                        }

//Keep the rest of the function

It seems to work. Enjoy!

Using WordPress as news column

When building my latest web site (Slipstream Longboards) I figured that I should use some existing tools for the news column. Since I had some knowledge about WordPress I decided to go with that. What I wanted was to use the nice WYSIWG editor WordPress and also to have a nice way to generate the RSS Feeds.

I started reading on the WordPress web site and found that there is a nice API for this type of sites (See the Codex pages).

Basically, this is what I did:

  1. Installed WordPress
  2. Moved and transformed the old data
  3. Outputed the data from WordPress to a non WordPress page
  4. Outputed the data from WordPress to a RSS Feed

I will describe how I did step two, tree and four below. For more information about installing WordPress see the WordPress web site.

Move and transform the old data

Since the old data was a limited amount of data (about 10 news posts) I figured that I should just output the data and then do some text manipulation which made it compliant to the MovableType format and then import it into WordPress. This turned out to work well and I had the data inserted into WordPress in less than an hour.

Output the data to a page outside of WordPress

To get the data from WordPress I used the WordPress loop which is a way to query the database and output the data. It is realy easy to use.

First you include a file from WordPress using:

define('WP_USE_THEMES', false);
require('./news/wp-blog-header.php');

Then you can use the WordPress Loop.

if ( have_posts() ) : while ( have_posts() ) : the_post();
// Output your data here
endwhile;

To output for example the title and the body for your posts you use:

if ( have_posts() ) : while ( have_posts() ) : the_post();
the_title();
the_content();
endwhile;

It is possible to restrict the data to only output for example posts with a different author or to only output posts in a specific category. See the Codex page for more information about this.

Output the data from WordPress to a RSS Feed

To customize the RSS Feed for this web site I simply copied the wp-rss2.php from WordPress and changed;

  1. the URL to the web site to point to the first page for the web site instead of the first page for the blog
  2. the URLs to each item to be displayed on the web site instead of the blog
  3. I also had to include the wp-blog-header.php file (all as done above) and remove the include for the wp-config.php and delete the the call to the wp(feed=rss2)

And that produced a nice feed.

New photo album!

Today we are done with our new photo album web site. It’s a small PHP application that I’ve build. You upload the image files to a directory. It creates the site and an RSS feed for you. You can also put a text file in every folder that’s printed as album description.

A screenshot of the first page

A screenshot of a typical album

Update: We used this for all our photos from 040612 to 060709