Paid affiliate advertisement
$50 Need help with themesettingsapi
I'm trying to use themesettingsapi to ask the user for 3 images on the theme settings page and then use those 3 images within the theme (2 images in the header and one in the footer).
I'm having trouble with this, so I'll pay $50 to the first person to send me an example that would work. I have the code for the form to request the image, but nothing beyond that. I'd need to see what you're adding to settings.php , template.php and page.tpl.php to make the images appear. Right now I have the following in settings.php
$form['MyTheme_HeaderImage'] = array(
'#type' => 'file',
'#title' => t('Upload Top Image'),
'#size' => 48,
'#description' => t('This image will appear on the top of your theme.')
);
You can email me at dcmeagle@goosemoose.com

Here's a working solution
Here's a working solution using the following...
drupal 5.x
themesettingsapi 5.x-2.7
You mentioned settings.php, so you might be on themesettingsapi 2.0, but I think this will still work. This is based on how system.module saves the logo and icon files.
Note that I'm saving the image paths in Drupal variables rather than as theme settings. I can't figure out exactly how that works, but this is functional and will get you started.
In your _settings function, just before adding your form elements, add something like this...
<?php
// Check for a new uploaded image, and use it.
if ($file = file_check_upload('myimage_upload')) {
if ($info = image_get_info($file->filepath)) {
$parts = pathinfo($file->filename);
$filename = 'mytheme_myimage.'. $parts['extension'];
// Save the image to the files directory using a predictable name.
if ($file = file_save_upload('myimage_upload', $filename, 1)) {
variable_set('myimage_path', $file->filepath);
drupal_set_message(t('Image uploaded successfully.'));
}
}
else {
form_set_error('file_upload', t('Only JPEG, PNG and GIF images are allowed.'));
}
}
?>
Then, in that same function, when you build your form elements below, do something like this...
<?php
$form['myimage_upload'] = array(
'#type' => 'file',
'#title' => t('Upload image'),
'#maxlength' => 40,
'#description' => t("If you don't have direct file access to the server, use this field to upload your logo.")
);
$form['myimage_path'] = array(
'#type' => 'textfield',
'#title' => t('Path to custom image'),
'#default_value' => variable_get('myimage_path', ''),
'#description' => t('The path to an image file for your theme.')
);
?>
Then you can either add the image paths to your template variables inside your _phptemplate_variables function, or simply use variable_get to retrieve them in page.tpl.php.
<img src="<?php print base_path(). variable_get('myimage_path', ''); ?>" alt="myimage">Let me know how this works out for you...
Chris.