I have a form and the person who fill it has the option to upload an image. The information is then stored in a table, with the person's name, e-mail, etc. and later shown in a page for the admin. I'm able to pull all the information, except I don't know how to store the image into the database and show it for the admin later. Hope you guys could understand
1条回答 默认 最新
- douan8473 2014-12-23 06:17关注
You don't store the images in the database, you store there path as a string
There is global variable called
$_FILES
just as$_GET
and$_POST
that contains all the info on the files uploaded. These are first stored in a temp directory. You usemove_uploaded_files
function to move them to a proper place. Then save the string in database.<?php $uploads_dir = '/uploads'; // Directory where you want to upload/keep all your pictures // Lets assume you sent the picture in `pictures` name field of form foreach ($_FILES["pictures"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["pictures"]["tmp_name"][$key]; $name = $_FILES["pictures"]["name"][$key]; move_uploaded_file($tmp_name, "$uploads_dir/$name"); // Save `$upload_dir/$name` in db } } ?>
Now when you want to load the image later, just query the column of the table that stores the images location and use it as
src
at frontend.本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 winform的chart曲线生成时有凸起
- ¥15 msix packaging tool打包问题
- ¥15 finalshell节点的搭建代码和那个端口代码教程
- ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
- ¥15 Centos / PETSc / PETGEM
- ¥15 centos7.9 IPv6端口telnet和端口监控问题
- ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
- ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
- ¥20 海浪数据 南海地区海况数据,波浪数据
- ¥20 软件测试决策法疑问求解答