I am working on a phonegap application where a user can select a picture from their phone and upload it to server.
I have successfully managed to have user upload to a file path on the server such as domain.com/uploads. The index.php file for that looks like this:
<?php
print_r($_FILES);
move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/".$_FILES["file"]["name"]);
?>
I want to take this further, and instead of storing pictures in the folder, I wanted them to go in to SQL. This index.php file looks like:
<?php
print_r($_FILES);
$image= addslashes($_FILES['image']['tmp_name']);
$name= addslashes($_FILES['image']['name']);
$image= file_get_contents($image);
$image= base64_encode($image);
saveimage($name,$image);
function saveimage($name,$image)
{
$con=mysql_connect("sqlserver","user","pass");
mysql_select_db("pics",$con);
$qry="insert into pics (name,image) values ('$name','$image')";
$result=mysql_query($qry,$con);
}
?>
My SQL table has 3 rows: id(int, a_i), name (varchar), image (longblob)
The JavaScript in my application does the following:
function uploadImage(imageData) {
var serverURL = "index.php";
var options = new FileUploadOptions();
options.FileKey = 'file'
options.fileName = imageData.substr(imageData.lastIndexOf('/')+1);
options.mimeType = "image/jpeg";
var ft= new FileTransfer();
ft.upload(imageData, serverURL, onUploadSuccess, onUploadError, options);
Once again, there is no issue with the JS file. The first index.php works fine, too.
I am learning every day, so an answer will be appreciated but an explanation will be even much more appreciated. My next steps will be displaying these uploaded pictures in JS file as thumbnails. If someone wants to give me heads on articles or tell me what I need to know I would very much appreciate it!