Blob 图像信息返回到 中标签?

发布于 2024-12-11 04:18:00 字数 1235 浏览 0 评论 0原文

我成功地通过表单标签和php将所有图像信息作为blob存储在MySQL中。 现在我正在尝试使用 PHP5 制作更新表单。但是,我不确定如何从 MySQL 取回所有信息并向用户显示图像已经发布。就像显示先前添加的文件的任何其他典型论坛/博客页面一样。

有什么建议吗..?谢谢。

<form method="post" enctype="multipart/form-data" action="UpdateNewsPHP.php">
Title  : <input name='TitleFieldToAdd' type='text' size='20' value='<?php echo $row["Title"] ?>'/> <br/>
Thread : <textarea name='ThreadFieldToAdd' cols="40" rows="10"><?php echo $row["Thread"] ?></textarea> <br/>
<!-- Here I have no clue how to deal with them... :( -->
Image  :  <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
<input type="file" id='ImageFieldToAdd' name="files[]" /> <br/>
<input id="submit" type="submit" name="submit" value="Upload me!">

这是我存储在 MySQL 中的信息

$title = $_REQUEST['TitleFieldToAdd'];
$thread = $_REQUEST['ThreadFieldToAdd'];
$file_content = file_get_contents($_FILES['files']['tmp_name'][0]);
$file_content = mysql_real_escape_string($file_content);
$file_name = $_FILES['files']['name'][0];
$file_size = $_FILES['files']['size'][0];
$file_type = $_FILES['files']['type'][0];
$datePosted = date("Y-m-d");*/

I succeeded in storing all the image information as a blob in MySQL via the form tag and php.
Now I'm trying to make an update form using PHP5. However, I'm not sure how to take all the information back from MySQL and show it to users that an image has been already posted.. like any other typical forum / blog pages that shows previously added files.

Any suggestions..? Thank you.

<form method="post" enctype="multipart/form-data" action="UpdateNewsPHP.php">
Title  : <input name='TitleFieldToAdd' type='text' size='20' value='<?php echo $row["Title"] ?>'/> <br/>
Thread : <textarea name='ThreadFieldToAdd' cols="40" rows="10"><?php echo $row["Thread"] ?></textarea> <br/>
<!-- Here I have no clue how to deal with them... :( -->
Image  :  <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
<input type="file" id='ImageFieldToAdd' name="files[]" /> <br/>
<input id="submit" type="submit" name="submit" value="Upload me!">

and this is the information I store in MySQL

$title = $_REQUEST['TitleFieldToAdd'];
$thread = $_REQUEST['ThreadFieldToAdd'];
$file_content = file_get_contents($_FILES['files']['tmp_name'][0]);
$file_content = mysql_real_escape_string($file_content);
$file_name = $_FILES['files']['name'][0];
$file_size = $_FILES['files']['size'][0];
$file_type = $_FILES['files']['type'][0];
$datePosted = date("Y-m-d");*/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡少年 2024-12-18 04:18:00

正确的方法是让您的文件上传内容保持原样。如果文件已上传,则将其显示在表单的另一部分。 Img 可以嵌入 标签(指向另一个从数据库检索/提供原始图像数据的脚本)。不可显示的字段(pdf、zip 等),您只需放入直接下载链接即可。

那么您的表单将看起来像

[input1]
[input2]
You previously uploaded: [link/image to uploaded data]
[input file] - would you like to replace this data?

这样,您的表单构建脚本实际上不会检索上传的文件数据。只是它的元数据(类型/大小)。

The proper way is to leave your file upload stuff asis. If a file has already been uploaded, you display it another section of the form. Imgs can be embedded with an <img> tag (pointing at another script which retrieves/serves up the raw image data from the database). Non-displayable fields (pdf, zip, etc..) you can just put in a direct download link.

Then your form will look something like

[input1]
[input2]
You previously uploaded: [link/image to uploaded data]
[input file] - would you like to replace this data?

As such, your form building script would not actually retrieve the uploaded file data. Just its metadata (type/size).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文