How to send input texts to PHP with Upload #763

Closed
lcg51 opened this Issue May 25, 2015 · 2 comments

Projects

None yet

3 participants

@lcg51
lcg51 commented May 25, 2015

Hi Im using ng-file-upload,for a project im developing. The issue is: How can I sent more data besides the file. In my form Im sending the data of the file and two text inputs to the server. Using the Upload method the file is sended without problem but the two inputs are not detected by the server.I don't know If Im sending wrong from the client or the server. Here's a part of my code.

That's how i send the file and the dat with upload:
Upload.upload({
url: 'http://localhost/degusto/uploadRecipe.php',
file: file,
method: 'POST',
data: {
nombre: recipe.nombre,
descrip: recipe.descrip},
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
...

Here's the server part(PHP):

$data = json_decode(file_get_contents('php://input'), true);

// Check if the two inputs are not null

if(isset($data['nombre']) && isset($data['descrip'])){

$n = $data['nombre'];
$d = $data['descrip'];
$date = date('Y-m-d');

$fichero = guardarImagen($_FILES['file'], 'img/',$_FILES['file']['name']);
                if($fichero=='')
                {
                    $R = array( "error"=>"No se pudo guardar el fichero");
                }

...
}

@aderowbotham
Contributor

Include a fields property in the object passed to Upload.upload().

Here is a working example from the project I am working on:

Upload.upload({
  url: '/api/files/upload',
  fields: {
    'fileContext': 'product',
    'editMode': $scope.editMode,
    'productSeed': $scope.product.seed
  },
  file: files,
  fileFormDataName: 'files[]'
}).progress(function (evt) {
  // ...
}).success(function (data, status, headers, config) {
  //...
});
@danialfarid danialfarid pushed a commit that referenced this issue Jun 4, 2015
Danial Farid Fixed #783 #764 #777 #766 #763 #761 #721 #687 #650 #710 #784 #768 #789 39fa784
@danialfarid
Owner

From version 5.0.0 instead of setting fileFormDataName you can set sendFieldsAs: "form"

@danialfarid danialfarid closed this Jun 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment