Uploading files with db_form

db_form can also handle uploaded files. The first thing to remember is that the form METHOD should be “POST” and that the ENCTYPE should be “multipart/form-data”.

  
  <form enctype="multipart/form-data" method="post">
  {{$frm.image}}
  {{$frm.submit}}
  </form>
  
  
  
  if ($_POST["action"]=="exampleupload") {
      $dbf->parseForm();
      //the following lines are here to document the available values
      $original_name=$dbf->getFormValue("image");
      $tmp_name=$dbf->getFormValue("image_tmp_name");
      $size=$dbf->getFormValue("image_size");
      $mime=$dbf->getFormValue("image_mime");
      //test if a file was uploaded or not
      if ($dbf->is_uploaded_file("image")) {
          move_uploaded_file($tmp_name, $final_destination);
      }
  }
  $dbf =& new db_form();
  $frm["image"]=$dbf->getFileInput("image", array("CLASS" => "textform"));
  $frm["submit"]=$dbf->getSubmit("submit", _l("Save"), array("CLASS" => "textform"))
      .$dbf->getHidden("action", "exampleupload");

  $_obweb->smslot->assign(array("frm" => $frm));
  
  

Available since Obliquid 0.7