0

I'm working on cordova project that uploads photos to server. While testing this for android, success callback is called but file not uploaded to server. Destination folder in server is present with necessary permission.

Following is the Javascript section

var options = new FileUploadOptions(); options.fileKey = "myphoto"; options.fileName = filetoupload.substr(filetoupload.lastIndexOf('/')+1); options.mimeType = "image/jpeg"; options.chunkedMode = false; options.headers = { Connection: "close" }; var ft = new FileTransfer(); ft.upload(filetoupload, encodeURI(websrvs_base_url), win, fail, options); 

In server PHP code is

<?php header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS"); header("content-type: application/json; charset=utf-8"); if($_FILES['myphoto']['size'] > 0) { $path = $ROOT_PATH . "mypics/"; $tmpname1 = $_FILES['myphoto']['tmp_name']; $ptname1 = $_FILES['myphoto']['name']; move_uploaded_file($tmpname1, $path . $ptname11); echo 'success'; } 

On checking $_FILES['myphoto']['error'] returns 7

Server has following setting regarding file upload

file_uploads - On

memory_limit - 128M

post_max_size - 64M

upload_max_filesize - 100M

Should I added any additional headers in PHP script to receive the file from app?

4
  • First, ensure that PHP is configured to allow file uploads. In your "php.ini" file, search for the file_uploads directive, and set it to On Commented Feb 16, 2016 at 12:28
  • @Naitik PHP yes it has necessary setting, see my edit Commented Feb 16, 2016 at 12:41
  • Pelease try with this example cordova.apache.org/docs/en/2.8.0/cordova/file/filetransfer/… Commented Feb 16, 2016 at 12:50
  • example is similar to what I have in the post Commented Feb 16, 2016 at 16:04

1 Answer 1

1

It turned out to be a server issue, our demo server was disk full and it didn't allow uploading photos from app.

We will have to check the space available for /tmp folder in server as this will be used as a temporary storage before uploading the file to actual destination. Files will not upload if /tmp folder is full or if there is any limitation.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.