当前位置:  开发笔记 > 编程语言 > 正文

如何使用PHP将文件上传到服务器时将文件名存储在数据库中以及其他信息?

如何解决《如何使用PHP将文件上传到服务器时将文件名存储在数据库中以及其他信息?》经验,为你挑选了1个好方法。

嗨,我已经阅读了很多论坛和网站,告诉你如何将图像上传到服务器,我已经设法让这个工作,我可以上传一个文件到我的服务器,但存储文件名确实适用于我发现的以下示例我还需要创建一个允许将更多数据输入数据库的表单.我坚持这个,因为之前做了很多PHP.我已经结束尝试不同的网站教程没有太大的成功,任何人都可以帮助我!我需要为我正在做的项目完成它.

我基本上试图建立一个CMS,允许用户上传乐队成员的照片并存储有关他们的信息,以便它可以显示在网页上供公众查看.


我的表看起来像这样:

Field              Type             Null    Default     
id                 int(10)          No                   
nameMember         varchar(25)      No                   
bandMember         text             No                   
photo              varchar(30)      No                   
aboutMember        text             No                   
otherBands         text             No      

我想要的表单如下所示:

   

Adding a new Band Member or Affiliate

Please Enter the Band Members Name.

Band Member or Affiliates Name:

Please Enter the Band Members Position. Example:Drums.

Member's Position:

Please Upload a Photo in gif or jpeg format. The file name should be named after the Members name. If the same file name is uploaded twice it will be overwritten!

Photo:

Please Enter any other information about the band member here.

Other Member Information:

Please Enter any other Bands the Member has been in.

Other Bands:



将Image上传到服务器的示例,即:

File ".$_FILES["filep"]["name"]."loaded...";

$result = mysql_connect("localhost", "******", "*****") or die ("Could not save image name

Error: " . mysql_error());

mysql_select_db("project") or die("Could not select database");
mysql_query("INSERT into dbProfiles (photo) VALUES('".$_FILES['filep']['name']."')");
if($result) { echo "Image name saved into database

"; }

}

?>

我必须使用的示例表单是这样的:

File:

PS:图像文件打开以便写入.



1> Cool Hand Lu..:

对于那些看起来像我在网上试图找到如何完成这项任务的人来说,这就是答案.将照片上传到服务器,文件名存储在mysql数据库中,以及数据库中需要的其他表单数据.如果有帮助,请告诉我.

首先是你需要的表格:

    

Please Enter the Band Members Name.

Band Member or Affiliates Name:

Please Enter the Band Members Position. Example:Drums.

Band Position:

Please Upload a Photo of the Member in gif or jpeg format. The file name should be named after the Members name. If the same file name is uploaded twice it will be overwritten! Maxium size of File is 35kb.

Photo:

Please Enter any other information about the band member here.

Other Member Information:

Please Enter any other Bands the Member has been in.

Other Bands:



然后,此代码处理来自表单的数据:

    

代码从www.about.com编辑

推荐阅读
爱唱歌的郭少文_
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有