开发者社区> 问答> 正文

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

嗨,我读过很多论坛和网站,它们告诉您如何将图像上载到服务器,并且设法将其上载,我可以将文件上载到服务器上,但是存储文件名确实适用于以下示例而且我还需要创建一个表单,以允许将更多数据输入数据库。我坚持这样做,因为之前已经做过很多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

  <form method="post" action="addMember.php" enctype="multipart/form-data">
   <p>
          Please Enter the Band Members Name.
        </p>
        <p>
          Band Member or Affiliates Name:
        </p>
        <input type="text" name="nameMember"/>
        <p>
          Please Enter the Band Members Position. Example:Drums.
        </p>
        <p>
          Member's Position:
        </p>
        <input type="text" name="bandMember"/>
        <p>
          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!
        </p>
        <p>
          Photo:
        </p>
        <input type="file" name="filep" size=35 />
        <p>
          Please Enter any other information about the band member here.
        </p>
        <p>
          Other Member Information:
        </p>

Please Enter any other Bands the Member has been in.

Other Bands:



该示例仅将图像上传到服务器,就是这样:

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:图像文件已打开,可以写入。

展开
收起
保持可爱mmm 2020-05-16 20:54:14 649 0
1 条回答
写回答
取消 提交回答
  • 这是您在我看来遍及网络上试图找出如何完成此任务的那些人的答案。使用存储在mysql数据库中的文件名以及您想要在数据库中的其他表单数据将照片上传到服务器。请让我知道是否有帮助。

    首先,您需要的表格:

    <form method="post" action="addMember.php" enctype="multipart/form-data">
    <p>
              Please Enter the Band Members Name.
            </p>
            <p>
              Band Member or Affiliates Name:
            </p>
            <input type="text" name="nameMember"/>
            <p>
              Please Enter the Band Members Position. Example:Drums.
            </p>
            <p>
              Band Position:
            </p>
            <input type="text" name="bandMember"/>
            <p>
              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.
            </p>
            <p>
              Photo:
            </p>
            <input type="hidden" name="size" value="350000">
            <input type="file" name="photo"> 
            <p>
              Please Enter any other information about the band member here.
            </p>
            <p>
              Other Member Information:
            </p>
    

    Please Enter any other Bands the Member has been in.

    Other Bands:



    然后,这段代码将处理来自表单的数据:

    来源:stack overflow
    2020-05-16 20:54:38
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
One Box: 解读事务与分析一体化数据库 HybridDB for MySQL 立即下载
One Box:解读事务与分析一体化数据库HybridDB for MySQL 立即下载
如何支撑HTAP场景-HybridDB for MySQL系统架构和技术演进 立即下载

相关镜像