我试着与使用文件传输API的发现得到的图像:PhoneGap的文件传输API到MySQL PHP
http://docs.phonegap.com/en/1.0.0/phonegap_file_file.md.html#FileTransfer
到MySQL数据库。我目前可以没有任何问题地将它送到服务器,但是我找不到任何教程/代码片段来说明如何将它送到Mysql。我目前有下面的代码,但它只是每次返回“没有图像选择”。
如果任何人有建议,链接等id非常伟大。
// Create MySQL login values and
// set them to your login information.
$username = "";
$password = "";
$host = "";
$database = "";
// Make the connect to MySQL or die
// and display an error.
$link = mysql_connect($host, $username, $password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// Select your database
mysql_select_db ($database);
// Make sure the user actually
// selected and uploaded a file
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {
// Temporary file name stored on the server
$tmpName = $_FILES['image']['tmp_name'];
// Read the file
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
// Create the query and insert
// into our database.
$query = "INSERT INTO tbl_images ";
$query .= "(image) VALUES ('$data')";
$results = mysql_query($query, $link);
// Print results
print "Thank you, your file has been uploaded.";
}
else {
print“No image selected/uploaded”; }
// Close our MySQL Link
mysql_close($link);