栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用PHP上传文件并将路径添加到MySQL数据库

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用PHP上传文件并将路径添加到MySQL数据库

首先,您应该使用它

print_r($_FILES)
进行调试,然后查看其中包含的内容。:

uploads.php
将看起来像:

//This is the directory where images will be saved$target = "pics/";$target = $target . basename( $_FILES['Filename']['name']);//This gets all the other information from the form$Filename=basename( $_FILES['Filename']['name']);$Description=$_POST['Description'];//Writes the Filename to the serverif(move_uploaded_file($_FILES['Filename']['tmp_name'], $target)) {    //Tells you if its all ok    echo "The file ". basename( $_FILES['Filename']['name']). " has been uploaded, and your information has been added to the directory";    // Connects to your Database    mysql_connect("localhost", "root", "") or die(mysql_error()) ;    mysql_select_db("altabotanikk") or die(mysql_error()) ;    //Writes the information to the database    mysql_query("INSERT INTO picture (Filename,Description)    VALUES ('$Filename', '$Description')") ;} else {    //Gives and error if its not    echo "Sorry, there was a problem uploading your file.";}?>

编辑:
由于这是旧帖子,目前强烈建议在php中使用mysqli或pdo代替mysql_函数



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/418731.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号