上传图片和信息

时间:2013-04-06 21:42:55

标签: php html5

我想创建一个表单,允许用户上传他们的照片,姓名和电子邮件,然后将其保存在数据库中? 到目前为止,我已经尝试了http://www.reconn.us/file_uploading.html

1 个答案:

答案 0 :(得分:1)

在链接解释时获取图像,然后读入临时文件并将其存储在数据库中的BLOB - 类型字段中。有关完整示例,请参阅here


// 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);
?>