I have been working on this code and I am having some errors, and I was wondering if anybody can find errors in this code... I have posted my error below it...
function background_audio_form($form, &$form_state) {
$form['background_audio_file']['file'] = array(
'#type' => 'managed_file',
'#title' => t('File'),
'#description' => t('Allowed extensions: mp3'),
'#upload_location' => 'public://MP3/',
'#default_value' => variable_get('background_audio_file'),
'#upload_validators' => array(
'file_validate_extensions' => array('gif png jpg jpeg mp3'),
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save Changes'),
);
return $form;
}
function background_audio_form_submit($form, $form_state) {
// The file is automatically uploaded and saved in the default
// validation process so you just need to load the file object at this point,
// mark that you want to keep it, and save it again.
// The file ID is contained in the $form_state['values'] array
$file = file_load($form_state['values']['background_audio_file']);
$file->status = FILE_STATUS_PERMANENT;
file_save($file);
$fid = $form_state['values']['background_audio_file'];
$fileid = file_load($fid);
variable_set('background_audio_upload_path', $fileid->uri);
}
Notice: Undefined index: background_audio_file in background_audio_form_submit() (line 107 of /Users/jtharpe/Overflow_Dev/sites/all/modules/background_audio/background_audio.module). Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /Users/jtharpe/Overflow_Dev/includes/entity.inc). Notice: Undefined property: stdClass::$uri in file_save() (line 573 of /Users/jtharpe/Overflow_Dev/includes/file.inc). PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'uri': INSERT INTO {file_managed} (filesize, status, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 0 [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => 1329961119 ) in drupal_write_record() (line 6975 of /Users/jtharpe/Overflow_Dev/includes/common.inc).
DrupalDefaultEntityController
object. There is no such kind of object in D6. – Sithu Feb 23 '12 at 7:52