1
私はカスタムモジュールを持っており、画像をアップロードするフィールドが必要です。 Chromeがファイルをアップロードしているように見えますが、機能していないため、以下のエラーが表示されます。誰かが私を正しい方向に向けることができますか?Drupal 7でファイルのアップロードが動作しないのはなぜですか?
function nafa_adoption_form($form_state)
{
$form['#attributes'] = array('enctype' => "multipart/form-data");
...
$form['picture'] = array(
'#type' => 'file',
'#title' => t('Picture'),
'#size' => 20,
'#upload_location' => 'public://uploads'
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
機能を提出してください:
function nafa_adoption_form_submit($form, &$form_state)
{
dvm($form_state['values']); //field 'picture' is blank
$file = file_load($form_state['values']['picture']);
$file->status = FILE_STATUS_PERMANENT;
file_save($file);
$fileid = file_load($file);
variable_set('adoption_picture', $fileid->uri);
if ($file)
{
drupal_set_message("File uploaded ");
}
else
{
drupal_set_message("File could not be uploaded");
}
drupal_set_message(t('Your form has been saved.'));
}
私はまた、次のエラーを取得:あなたはdocs for the file
element typeあなたが気づく見れば
Notice: Undefined property: stdClass::$uri in file_save() (line 573 of /home/amn7940/nafa.achristiansen.com/includes/file.inc).