Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to send input texts to PHP with Upload #763

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

How to send input texts to PHP with Upload #763

lcg51 opened this issue May 25, 2015 · 2 comments

Comments

@lcg51
Copy link

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
Copy link
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 pushed a commit that referenced this issue Jun 4, 2015
@danialfarid
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants