3

我在使用 Drupal 7 和文件上传时遇到问题。

我的代码不起作用:

function test_form($form, &$form_state){

$form['#attributes'] = array('enctype' => "multipart/form-data");
$form['podcast'] = array(
    '#title' => 'Audio file',
    '#type' => 'file',
);
$form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
);
return $form;

}

function test_form_submit($form, &$form_state){

$vals = $form_state['values'];
$filepath = 'public://test/';
//$filepath = 'temporary://test/';
$filename = 'rcc_date.mp3';

file_prepare_directory($filepath, FILE_CREATE_DIRECTORY);
$file = file_save_upload('podcast', array('file_validate_extensions' => array()), $filepath.$filename);
//got FALSE here. Why?
die(print_r($file===FALSE).'-');

}

因此创建了路径,但文件未上传,并且 file_save_upload 返回 FALSE。我也尝试了 array() 和 true 作为 $validators 没有效果。

非常感谢任何帮助。谢谢。

4

1 回答 1

4

多哈。$destination 不应该包含文件名,只包含路径。

于 2010-11-20T15:58:39.993 回答