我试图使用在以下位置找到的文件传输API来获取图像:
http://docs.phonegap.com/en/1.0.0/phonegap_file_file.md.html#FileTransfer
到Mysql数据库。我现在可以将它连接到服务器而没有任何问题,但是我找不到任何教程/代码片段,你将如何获得它到Mysql。我目前有以下代码,但每次只返回“没有选择图像”。
如果有人有建议,那么链接等非常好。
// 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 {
打印“未选择/上传图像”; }
// Close our MySQL Link
mysql_close($link);
答案 0 :(得分:0)
看看那个教程。它不包括MySQL,但将图片保存在PHP服务器上:
答案 1 :(得分:0)
$_FILES['image']['error'] == UPLOAD_ERR_OK
以确保成功上传DID。file_get_contents()
将为您轻松做到这一点。mysql_query(...) or die(mysql_error());
作为一个最小的选项。