我試着與使用文件傳輸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);