PHP脚本与数据库功能详解(中)

上一篇:PHP脚本与数据库功能详解(上)

利用PHP将文件保存到数据库
  数据库是数据组织、存储的中心。将要处理的也可能是各种数据,包括程序、文件、报表,甚至音频、视频数据。由于通过浏览器,个人用户只能填写少部分的个人简历。因此,我们这里示范用户个人简历上载的功能。其他类型的数据可以模仿此例进行操作。

  首先是信息收集页面。让用户选择要上载的文件。此页面的html代码如下:

  〈!– begin of post.htm–〉

  〈p〉 〈/p〉

  〈form method="POST" action="insert.php" ENCTYPE="multipart/form-data"〉

  〈p〉〈b〉个人简历提交〈/b〉〈/p〉

  〈p〉姓名:〈br〉

  〈input type="text" name="Name" size="20"〉〈/p〉

  〈p〉个人简介:〈br〉

  〈textarea rows="2" name="Intro" cols="20"〉〈/textarea〉〈/p〉

  〈p〉简历文件:〈br〉

  〈input type="file" name="ResuFile"〉〈/p〉

  〈p〉〈input type="submit" value="提交" name="B1"〉〈/p〉

  〈/form〉

  〈!-End of post.htm–〉

  注意,ENCTYPE关键字一定不能省,否则文件无法正确上载。

  这里,我们再把向数据库插入记录的代码重新设计:

  〈?

  //begin of file insert.php

  if($ResuFile != "none")

  //确定用户选择了文件

  {

  $Size = filesize($ResuFile);

  //确定文件大小

  $mFileData = addslashes(fread(fopen($ResuFile, "r"), $Size));

  //读取文件,对内容进行处理

  unlink($ResuFile);

  //删除上载临时文件

  }

  $LinkID=@mysql_connect("localhost", "root" , "") or die("不能连接到数据库服务器!可能是数据库服务器没有启动,或者用户名密码有误!");

  $DBID = @mysql_select_db("ResumeDB",$LinkID) or die("选择数据库出错,可能是您指定的数据库不存在!");

  $query = "insert into Resume(Name,Intro,ResuFile) values(‘$Name’, ‘$Intro’, ‘$mFileData’)";

  $result = @mysql_query("$query",$LinkID); //执行查询,插入文件到数据库

  if(! $result)

   echo "数据插入失败!";

  else

   echo "文件上载成功!";

  @mysql_close($LinkID);

  //end of file insert.php

  ?〉

  有了上面的基础,写出从数据库读数据的程序应该很简单了。需要注意的是文件向客户发送的方法。服务器必须向浏览器发送头信息,说明将要发送的数据为word文档。如果用户计算机装有MSWord,浏览器将自动调用word进行文档显示。

  我们可以设置一个超级链接,来下载这个Word文件:

  〈?

  //begin of file show.php

  $LinkID=@mysql_connect("localhost", "root" , "") or die("不能连接到数据库服务器!可能是数据库服务器没有启动,或者用户名密码有误!");

波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!

波比源码 » PHP脚本与数据库功能详解(中)

124 评论

  1. buy cialis 40mg online cheap buy cheap cialis viagra sildenafil 25mg

  2. order prograf 5mg prograf uk buy ursodiol 300mg pill

  3. buy glycomet 1000mg without prescription cheap cialis 40mg order cialis 5mg without prescription

  4. tadalafil 20mg without prescription cialis 10mg ca clopidogrel 75mg brand

  5. golden nugget online casino slots games order tadalafil 5mg sale

  6. cost of viagra 100mg viagra next day cialis 10mg for sale

  7. planning poker online play poker online play for real online casino games

  8. Thank you for content. Area rugs and online home decor store. Hello Administ . Metropol Halı Karaca Halı Öztekin ve Selçuklu Halı Cami Halısı ve Cami Halıları Türkiye’nin En Büyük Cami Halısı Fabrikasıyız…

  9. tricor 160mg oral viagra us buy viagra 50mg for sale

  10. purchase fildena pills finasteride pills order propecia without prescription

  11. order levaquin without prescription buy levaquin pills purchase bupropion online cheap

  12. order warfarin 5mg generic zyloprim ca buy zyloprim 100mg for sale

  13. generic cenforce 100mg order cenforce glucophage 1000mg usa

  14. stromectol ivermectin buy stromectol pills buy isotretinoin no prescription

  15. buy prednisolone tablets furosemide 100mg us buy furosemide 100mg online cheap

  16. order levoxyl generic levitra pills vardenafil 20mg brand

  17. buy tetracycline 250mg without prescription lioresal pills baclofen 25mg usa

  18. starlix 120 mg without prescription atacand drug where to buy candesartan without a prescription

  19. clonidine 0.1 mg cost spiriva 9mcg cheap buy generic tiotropium bromide 9mcg

  20. how to get clopidogrel without a prescription plavix 75mg sale warfarin 2mg canada

  21. purchase erythromycin for sale nolvadex 20mg ca order tamoxifen 20mg pills

  22. cordarone for sale online carvedilol sale dilantin online buy

  23. aviator oyunu hilesi apk
    aviator taktikleri

  24. oxytrol without prescription buy fosamax pill buy generic alendronate online

  25. glucotrol over the counter cost glipizide buy betnovate 20gm generic

  26. buy tindamax pill tindamax drug cost nebivolol 5mg

评论已关闭

Hi, 如果你对这款模板有疑问,可以跟我联系哦!

联系站长
赞助VIP 享更多特权,建议使用 QQ 登录
喜欢我嘛?喜欢就按“ctrl+D”收藏我吧!♡