drvc63490 2015-08-31 14:21
浏览 368
已采纳

使用1个提交按钮上传多个文件/图片

I want to upload and store multiple files/pics path in database with 1 submit button ...... This is what i am doing in html form

Icon:
<br>
<br>
<input type="file"     name="uploadedfile" >
<br>
<br>
Screenshot:
<br>
<br>
<input type="file"  name ="fileToUpload"> 
<br>

And this is my php code

<?php 

if (isset($_POST['submit'])){
$target_dir= "images/";
$target_file= $target_dir.basename($_FILES['uploadedfile']['name']);
$tmp=$_FILES['uploadedfile']['tmp_name'];
if (move_uploaded_file($tmp,$target_file) ){

    echo "uploaded successfully";

}
else {
    echo "not uploaded successfully";
}

$targets_dir= "images/";
$targets_file= $targets_dir.basename($_FILES['fileToUpload']['name']);
$tmps=$_FILES['fileToUpload']['tmp_name'];

if (move_uploaded_file($tmps,$targets_file) ){

    echo "uploaded successfully";

}
else {
    echo "not uploaded successfully";
}

$insert=" insert into app values  (DEFAULT,'$Title', '$target_file' , '$targets_file'  )";

}

But its not working ...... Any advice will be appreciated .. Thanks in advance

  • 写回答

2条回答 默认 最新

  • dongyi7513 2015-08-31 14:40
    关注

    Use this code, u just need to insert the query. Rest everything will work fine.

     if ((!empty($_FILES['uploadedfile']["name"])) && (!empty($_FILES['fileToUpload']["name"])))
    {
    
    $file_name1=$_FILES['uploadedfile']["name"];
    $temp_name1=$_FILES['uploadedfile']["tmp_name"];
    $imagename1=date("d-m-Y")."-".time();       
    $target_path1 = "images/".$imagename1;
    $Rtarget_path1 = "images/".$imagename1;
    
    $file_name2=$_FILES['fileToUpload']["name"];
    $temp_name2=$_FILES['fileToUpload']["tmp_name"];
    $imagename2=date("d-m-Y")."-".time();       
    $target_path2 = "images/".$imagename2;
    $Rtarget_path2 = "images/".$imagename2;
    
       if((move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $Rtarget_path1 )) && (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $Rtarget_path2 )))
        {
            $insert=" insert into app values  (DEFAULT,'$Title', '$target_path1' , '$target_path2'  )"; // Insert Query Wrong. Also Check Here
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键