Php 如何上传多个文件,将其路径存储在mysql数据库行的不同列中

Php 如何上传多个文件,将其路径存储在mysql数据库行的不同列中,php,mysql,file,upload,path,Php,Mysql,File,Upload,Path,您好,我正在尝试创建一个订阅表单,允许用户填写表单并上载多个文件。 我已经在这个网站上得到了一些关于上传文件和使用此文件将其路径存储在数据库中的指导 <form method="post" action="addMember.php" enctype="multipart/form-data"> <p> Please Enter the Band Members Name. </p>

您好,我正在尝试创建一个订阅表单,允许用户填写表单并上载多个文件。 我已经在这个网站上得到了一些关于上传文件和使用此文件将其路径存储在数据库中的指导

     <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>
<textarea rows="10" cols="35" name="aboutMember">
</textarea>
            <p>
              Please Enter any other Bands the Member has been in.
            </p>
            <p>
              Other Bands:
            </p>
            <input type="text" name="otherBands" size=30 />
            <br/>
            <br/>
            <input TYPE="submit" name="upload" title="Add data to the Database" value="Add Member"/>
          </form>
and the php code for inserting this

   <?php

//This is the directory where images will be saved
$target = "your directory";
$target = $target . basename( $_FILES['photo']['name']);

//This gets all the other information from the form
$name=$_POST['nameMember'];
$bandMember=$_POST['bandMember'];
$pic=($_FILES['photo']['name']);
$about=$_POST['aboutMember'];
$bands=$_POST['otherBands'];


// Connects to your Database
mysql_connect("yourhost", "username", "password") or die(mysql_error()) ;
mysql_select_db("dbName") or die(mysql_error()) ;

//Writes the information to the database
mysql_query("INSERT INTO tableName (nameMember,bandMember,photo,aboutMember,otherBands)
VALUES ('$name', '$bandMember', '$pic', '$about', '$bands')") ;

//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
但我想做的是有多个上传字段,并将它们的路径存储在不同的列中photo,photo1,photo2 e、 g


id姓名成员乐队成员照片1照片2关于成员其他乐队

请问我该怎么做

您必须更改他们的身份

$pic1=($_FILES['photo1']['name']);
$pic2=($_FILES['photo2']['name']);
$pic3=($_FILES['photo3']['name']);
for($i=1;$i<=3;$i++)
{
if(move_uploaded_file($_FILES['photo'.$i]['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
}
and in your query you can change it with like a

    mysql_query("INSERT INTO tableName 
               (nameMember,bandMember,photo,photo1,photo2,aboutMember,otherBands)
               VALUES ('$name', '$bandMember', '$pic','$pic1','$pic2', '$about', '$bands')") ;
$pic1=($_文件['photo1']['name']);
$pic2=($_文件['photo2']['name']);
$pic3=($_文件['photo3']['name']);

对于($i=1;$iall输入应该保持id的不同。检查完后$\u文件谢谢,但这简短的解释没有帮助,我想将不同的路径存储在同一行的不同列中。您没有提到将其写入服务器部分意味着您想说的是,我如何处理多个文件上载到那里很好。i在这个链接上也有一个解决方案,
 <input type="file" name="photo"> 
 <input type="file" name="photo1"> 
 <input type="file" name="photo2"> 
id nameMember bandMember photo photo1 photo2 aboutMember otherBands
$pic1=($_FILES['photo1']['name']);
$pic2=($_FILES['photo2']['name']);
$pic3=($_FILES['photo3']['name']);
for($i=1;$i<=3;$i++)
{
if(move_uploaded_file($_FILES['photo'.$i]['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
}
and in your query you can change it with like a

    mysql_query("INSERT INTO tableName 
               (nameMember,bandMember,photo,photo1,photo2,aboutMember,otherBands)
               VALUES ('$name', '$bandMember', '$pic','$pic1','$pic2', '$about', '$bands')") ;