1

when i tried the application, everything works perfectly. success log is appear.but when i check in my server, there are no photos.

this is my code.

script.js

$('#gallery_page').live('pageshow', function(){
getGallery();
$('#library').bind('click', function(){
    photo_library();
    getGallery();
});
});

function photo_library(source) {
var pictureSource;   // picture source
var destinationType; // sets the format of returned value 

document.addEventListener("deviceready",onDeviceReady,false);

function onDeviceReady() {
    pictureSource=navigator.camera.PictureSourceType;
    destinationType=navigator.camera.DestinationType;
};

navigator.camera.getPicture( uploadPhoto, onFail, { quality: 50, 
    destinationType: destinationType.FILE_URI,
    sourceType: pictureSource.PHOTOLIBRARY });
};

function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(imageURI, "http://*my_ip*/TA/php/upload.php", win, fail, options, true);
};

upload.php

include 'db.php';
print_r($_FILES);
$new_image_name = "namethisimage.jpg";
move_uploaded_file($_FILES["file"]["tmp_name"], "http://*my_ip*/TA/php/".$new_image_name);
Wen Hau
  • 11
  • 4
  • Have you checked your folder and script permissions? They both should have the same user/group. If you're running Apache,it would be something like apache:apache. From the cmd line you can run chown apache:apache upload.php then chown -R apache:apache php/ – rwhite May 26 '13 at 03:13
  • @rwhite35 can u tell me from the first?im confused..still new in phonegap n php – Wen Hau May 26 '13 at 03:34
  • from cmd, the directory is set to where? – Wen Hau May 26 '13 at 03:34
  • The function move_upload_file([source],[destination]). The path to your images folder should be somewhere under your web site root directory. The uploaded files are moved from /tmp to your upload folder. That folder(and script doing the work) needs to be owned by apache. Hope that makes sense. – rwhite May 26 '13 at 17:19

1 Answers1

1

This line should be changed

move_uploaded_file($_FILES["file"]["tmp_name"], "http://*my_ip*/TA/php/".$new_image_name);

to

move_uploaded_file($_FILES["file"]["tmp_name"], "/PATH/ON/SERVER/TA/php/".$new_image_name);

The code should look something like this:

upload.php

include 'db.php';
print_r($_FILES);
$new_image_name = "namethisimage.jpg";
move_uploaded_file($_FILES["file"]["tmp_name"], "/var/www/php/".$new_image_name);
Andrew Pearson
  • 317
  • 2
  • 12