I use the following code to upload images should be used in slideshow of the theme settings theme-settings.php:

for ($i = 0; $i < 7; $i++){
      $form['best_responsive_settings']['slideshow']['slideimages'][] = array(
        '#type' => 'managed_file',
        '#title' => t('Image').' #'.$i,
        '#upload_location' => file_default_scheme() . '://theme/backgrounds/',
    '#default_value' => theme_get_setting('background_file'), 
    '#upload_validators' => array(
      'file_validate_extensions' => array('gif png jpg jpeg')),


Those files are uploaded to: sites\default\files\theme\backgrounds I want to change the uploading location to sites\all\themes\best_responsive\images\backgrounds. How could I change '#upload_location' to do that?

1 Answer 1


It doesn't look like the file module places any restriction on the upload path, so in theory it should be as simple as:

'#upload_location' => DRUPAL_ROOT . '/' . drupal_get_path('theme', 'MYTHEME') . '/images/backgrounds';

However, having your theme folder writable by the web server would usually indicate that permissions are not set correctly. It would be a better idea to fix those, and save your images in the proper location (i.e. sites/default/files); see Securing file permissions and ownership for full details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.