dongsu3654 2017-11-13 09:41
浏览 57
已采纳

找不到该文件并上传

I trying to do multiple image upload to the system but it won't able to found the images after upload. When i try to var_dump the total number of item uploaded it keep showing 0 item uploaded.

Need some help here, Thank You.

This is my HTML code:

<form id="login-form" action="" method="post" enctype="multipart/form-data" >
    <input type="file" name="file[]" multiple="multiple"  />
<input type="submit" name="submit-scam" value="Submit">
</form>

This is my PHP code:

<?php
//Check Error
error_reporting(E_ALL);
//Start Session
session_start();
//Include Database
include_once('dbConnect.php');


if (isset($_POST['submit-scam'])){
    echo "button clicked";

if(isset($_FILES['file'])){ 

            /*This Function is to loop multiple upload file into DB*/

    $total = count($_FILES['file']['name']);

    for ($i=0; $i<$total; $i++) {

    $file = rand(1000,100000)."-".$_FILES['file']['name'][$i];
    $file_loc = $_FILES['file']['tmp_name'][$i];
    $file_size = $_FILES['file']['size'][$i];
    $file_type = $_FILES['file']['type'][$i];
    $folder="uploads/";
    $today = date('Y-m-d');

    // new file size in KB
    $new_size = $file_size/1024;  
    // new file size in KB

    // make file name in lower case
    $new_file_name = strtolower($file);
    // make file name in lower case

    $final_file=str_replace(' ','-',$new_file_name);


    if(move_uploaded_file($file_loc,$folder.$final_file))
    {

                    //To Insert Latest base to SQL Latest submit ec_claim id 

                    $sql="INSERT INTO db_evidence(db_evidence_name,db_evidence_type,db_evidence_scam_id,db_evidence_users_id) 
                    VALUES('$final_file','$file_type','1','1')";
                    $result = mysqli_query($connection, $sql) or die(mysqli_error($connection));
                    echo "success upload";
                    // header("Location:index.php");
                }
                else
                {
                    echo "failed to upload";
                }
                }
            } else {
                echo "error no file is found";
            }
}
?>
  • 写回答

1条回答 默认 最新

  • dsff788655567 2017-11-13 09:43
    关注

    Add enctype="multipart/form-data" to the form

    <form id="login-form" action="" method="post" enctype="multipart/form-data">
        <input type="file" name="file[]" multiple="multiple"  />
        <input type="submit" name="submit-scam" value="Submit">
    </form>
    

    That should let you read from type="file"

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

报告相同问题?

悬赏问题

  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的