使用PHP将图像上传到mysql数据库 [英] Image Uploading to mysql database using PHP
本文介绍了使用PHP将图像上传到mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将图像上传到 mysql 表.选择图像后,它工作正常.但是没有选择图像,它会显示错误消息.我该如何解决?
I'm trying to upload image to mysql table. When image selected it's working fine. But without selecting image it's display error message. How can i fix it?
警告:file_get_contents():文件名不能为空C:\wamp\www\firstdialnew\firstdial\adhandler.php 第 23 行
Warning: file_get_contents(): Filename cannot be empty in C:\wamp\www\firstdialnew\firstdial\adhandler.php on line 23
$stype=$_POST['stype'];
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['image']['name']);
if($stype="")
{
echo "Please fill all the details";
}else{
$sql=mysql_query("INSERT INTO ads
(sid,stype,image,image_name)
VALUES(NULL,'$stype','$image','$image_name')");
echo "Details Successfully send";
}
推荐答案
您需要检查/验证图像是否已上传或不尝试类似的操作
you need to check/validate that image is upload or not try something like that
if (!empty($_FILES['image']['name'])) {
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['image']['name']);
}else{
$image = '';
$image_name = '';
}
这篇关于使用PHP将图像上传到mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文