【发布时间】:2015-01-01 16:07:49
【问题描述】:
如何在 MySQL 数据库中存储和显示图像。到目前为止,我只编写了从用户那里获取图像并将它们存储在文件夹中的代码,我到目前为止编写的代码是: HTML 文件
<input type="file" name="imageUpload" id="imageUpload">
PHP 文件
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["imageUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if (move_uploaded_file($_FILES["imageUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["imageUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";}
【问题讨论】:
-
我不建议将图像存储在数据库中,您目前所做的是更好的方法。您需要做的就是将图像的路径存储在数据库中
-
感谢您的帮助,我想通了。现在我只是将上传文件的名称存储在我的数据库中并检索该名称以在我想要的任何位置打开图像。
标签: php html mysql image-uploading