我想创建允许用户上传他们的照片、姓名和电子邮件然后将其保存在数据库中的表单?
到目前为止,我已经尝试过了http://www.reconn.us/file_uploading.html
问问题
48 次
1 回答
1
按照链接说明获取图像,然后读入临时文件并将其存储在BLOB
数据库的 -type 字段中。有关完整示例,请参见此处。
// 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);
?>
于 2013-04-06T22:03:20.910 回答