I have the following code in my form.
function video_subtitles_menu() {
$items = array();
$items['video_subtitles_test/upload'] = array(
'title' => 'Upload Subtitle', //page title
'description' => 'Uploading subtitle for videos',
'page callback' => 'drupal_get_form',
'page arguments' => array('video_upload_subtitles_form'),
'access callback' => TRUE
);
return $items;
}
function video_upload_subtitles_form($form, &$form_state) {
$form = array('#attributes' => array('enctype' => 'multipart/form-data'));
$form['video_name'] = array(
'#title' => t('Name Of the video'),
'#type' => 'textfield',
);
$form['sub_file'] = array(
'#type' => 'file',
'#title' => t('Upload video'),
'#size' => 48,
'#description' => t('Pick a video file to upload.'),
);
$form['submit_button'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
function video_upload_subtitles_form_validate() {
if (!file_check_upload('upload')) {
form_set_error('upload', 'File missing for upload.');
}
}
function video_upload_subtitles_form_submit($form, &$form_state) {
$video_name = $form_state['values']['video_name'];
$file = file_save_upload('sub_file', array());
print "<pre>";print_r($file);// no response here
drupal_set_message(t('The form has been submitted.'));
}
On the submission handler, it only returns the text field. I don't get anything from file upload field, when I use file_save_upload()
.
This is the response which I get in Firebug. I tried uploading text and Excel files.
What I am trying to do is creating a block where users can upload a file; I then need to get to upload it to a CDN.
file_save_upload
returns An object containing the file information if the upload succeeded, FALSE in the event of an error, or NULL if no file was uploaded.. So if you your result isNULL
, it means no file was uploaded, and you should probably look into your server config. If it wasFALSE
, it means there was an error which you can find in your server logs or Drupal's watchdog (or both). 99 times out of 100 failures are due to permissions problems