Users uploading photos

Here is some example code using the Upload class: Allow guests to create pages from Panel or frontend

After the file is uploaded, you can use $page->update() to update the page. Here is a little function for updating a structure field:

function addToStructure($page, $field, $data = array()){
      $fieldData = page($page)->$field()->yaml();
      $fieldData[] = $data;
      $fieldData = yaml::encode($fieldData);
      try {
        page($page)->update(array($field => $fieldData));
        return true;
      } catch(Exception $e) {
        return $e->getMessage();
      }
    }
3 Likes