0

The below code works absolutely fine when i run on my local computer. However, i am building a mobile app using HTML5, CSS3, JAVASCRIPT,jquery-mobile using the cordova phonegap plugin.

If you look at the form element below i have an action attribute that calls a php file located on a web server. This will be impossible to call if i am building a mobile app right because they are located on different servers ? . In this case i cannot make an ajax call because i am transferring an image because you can't upload files using Ajax.?

How do i send an image from my mobile application the the php file on the web server then ?

1) index.html (Will build a Phone Gap app an distribute to users )

 <form action="php/updateProfilePicture.php" method="post" data-ajax="false" enctype="multipart/form-data">
 <label for="file">Update Profile Picture:</label>
 <input type="file" name="file" id="file"><br>
 <input type="submit" name="submit" value="Submit">
 </form>

2) updateProfilePicture.php (on the web server)

<?php 

$con = mysqli_connect("localhost", "root", "root123", "xyz", "3306");
mysqli_select_db($con, "xyz");

$email = 'xyz@gmail.com';

$stmt = $con->prepare('UPDATE  profileinformation SET Image = ? Where email = ? ');
$null = null;
$stmt->bind_param('bs',$null, $email);
$stmt->send_long_data(0, file_get_contents($_FILES['file']['tmp_name']));
$stmt->execute();

if ($stmt->errno) {
        echo "FAILURE!!! " . $stmt->error;
}

$stmt->close();

    ?>
dev_marshell08
  • 1,051
  • 3
  • 18
  • 40
  • possible duplicate of [Unable to update image in MySql DB using PHP prepared statement?](http://stackoverflow.com/questions/23587985/unable-to-update-image-in-mysql-db-using-php-prepared-statement) – Marc B May 11 '14 at 04:57
  • @MarcB this is not a duplicate here i am trying to run this code for my mobile app that i am building using PhoneGap Cordova plugin. In which case i cannot use the action attribute to make a call to the PHP file located on the web server. Thus i am seeking an alternate approach to that problem – dev_marshell08 May 11 '14 at 04:59
  • @dev_marshell08: Did you take a look at [this question](http://stackoverflow.com/a/15205612/1438393)? – Amal Murali May 11 '14 at 05:00
  • @AmalMurali that link does not help me because i cannot upload image using Ajax plus i am building an app for Apple iOs and Andriod thus the first approach will not work too in this case for an iOs application since apple will simply reject my app since Apple’s own guidelines state, “Apps that download code in any way or form will be rejected”. Which means that you need to have a distinctive separation of client and server side. – dev_marshell08 May 11 '14 at 05:18
  • Amal Murali's reference is correct solution for you. Basically you have to do two things, one create server with JSON data to accept your image and second create a client which drop image using ajax. Please see these codes resemble to your solution but in node.js https://github.com/ccoenraets/PictureFeed – Kamal Panhwar May 11 '14 at 09:57

0 Answers0