Skip to content
Philip Saa edited this page Jun 21, 2016 · 7 revisions

Contributed by PhilCowart and JaisonErick Updated by Philip Saa

Often sending data to the server, along with the file itself, is needed. Using PHP you'll often use the $_FILES global to get the file itself and the $_POST global to get the other fields values. Here are two examples using ngf-upload to send files to PHP backend scripts.

Sending additional data

Upload.upload({
    url: 'api/upload-image.php', 
    method: 'POST',
    file: file,
    data: {
        'awesomeThings': $scope.awesomeThings,
        'targetPath' : '/media/'
    }
})

You can handle the data on the backend like this:

  $filename = $_FILES['file']['name'];
  $meta = $_POST;
  $destination = $meta['targetPath'] . $filename;
  move_uploaded_file( $_FILES['file']['tmp_name'] , $destination );