doucezhu3570 2016-08-09 18:40
浏览 107
已采纳

多个文件上传,如何包含更多字段并添加数据库的完整路径

I found some code that uploads a file to a folder on my server and then saves the path to a database table column. the code for the form:

 <form method="post" action="add_member.php" enctype="multipart/form-
 data">
<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="cert_1">
           <br/>
            <br/>
          <input TYPE="submit" name="upload" title="Add data to the 
Database" value="Add Member"/>
</form>

And then the script with the algo that moves the file to the upload folder and then adds the full path to the database column

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

 //This gets all the other information from the form

   $pic=($_FILES['cert_1']['name']);



// Connects to your Database
mysql_connect("host", "db_user", "_db_pass") or         

die(mysql_error()) ;
mysql_select_db("your_db") or die(mysql_error()) ;

//Writes the information to the database
mysql_query("INSERT INTO student_biodata_master 
           (cert_1)
           VALUES ('$pic')") ;

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

//Tells you if its all ok
echo "The file ". basename( $_FILES['cert_1']['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.";
}

Now, I need to increase the number of file upload fields to four at the least and then write the full path of the files to the database columns respectively. The script works very well but only does not write the full path into the database so i can call it later and display in my application. Can "anygoodbody" help with this? its actually doing my head in.

Thanks in advance for the great advice always.

Stack Overflow rocks!

  • 写回答

1条回答 默认 最新

  • dongyong5255 2016-08-09 18:44
    关注

    You need html5 supported browser for multiple upload or use different technologies: java applet, flash, silverlight. jquery has a plugin for multiple upload: http://blueimp.github.io/jQuery-File-Upload/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来