I am trying to do file upload based on drupal api. the problem is that files are not uploaded and there is not any error. I have only information generated by this code "upload error". what is wrong here?


function internet_zdjecia_form($form_state) {

     $form = array();
     $form['#attributes'] = array('enctype' => "multipart/form-data");
     $form['zdjecia'] = array(
          '#type' => 'fieldset',
          '#title' => 'Zdjęcia instalacji',
          '#tree' => TRUE,
     );
     $form['zdjecia']['zdjecie1'] = array(
          '#type' => 'file',
          '#title' => 'Zdjęcie 1',
     );
     $form['zdjecia']['submit'] = array(
          '#type' => 'submit',
          '#value' => 'Dodaj',
     );
     return $form;
}

function internet_zdjecia_form_submit($form, &$form_state) {

     $validators = array();
     $file = file_save_upload('zdjecie1', $validators, 'files/internet/', TRUE);

     if (!$file) {
          drupal_set_message("Upload error!");
     }
}

Comments

Ravi.J’s picture

Check if files/intranet folder has write permissions, also check if filesize is within allowed max_upload_size.
Also take a look at error log on the server.

Arek’s picture

this code returns "OK":

$dir = 'files/internet';
if (file_check_directory($dir)) {
   echo 'OK';
} else {
   echo 'ERROR';
}

filesize is ok, I am trying upload simple (small) jpg file. I can't get error logs because my host provider do not have it...

I enabled upload module and it looks the same: when I push 'attach' button it looks like file is uploaded and after that everything looks like nothing happend (there is no attached file and no error)

I have modified file_save_upload function:

  // If a file was uploaded, process it.
if (isset($_FILES['files']) && $_FILES['files']['name'][$source] && is_uploaded_file($_FILES['files']['tmp_name'][$source])) {

...

} else {
  drupal_set_message('file not uploaded');
}

result: message "file not uploaded"

what else can I check?