0

下面我有一个处理文件输入的 iframe:

var $fileVideo = $("<form action='videoupload.php' method='post' enctype='multipart/form-data' target='upload_target_video' onsubmit='return videoClickHandler(this);' class='videouploadform' >" + 
"Video File: <input name='fileVideo' type='file' class='fileVideo' /></label>" +  
"<input type='submit' name='submitVideoBtn' class='sbtnvideo' value='Upload' /></label>" + 
 "<p class='listVideo' align='left'></p>" +
"<iframe class='upload_target_video' name='upload_target_video' src='/' style='width:0px;height:0px;border:0px;solid;#fff;'></iframe></form>"); 

现在我在下面有一个函数,当文件停止上传并成功上传到服务器时,它将显示上传文件的名称:

    function stopVideoUpload(success, videofilename){

      var result = '';
      videocounter++;

      if (success == 1){
         result = '<span class="videomsg'+videocounter+'">The file was uploaded successfully</span>';
          $('.listVideo').eq(window.lastUploadVideoIndex).append('<div>' + htmlEncode(videofilename) + 
          '<input type="text" name="videoidhide" value=""/><br/><hr/></div>');
      }


      return true;   
}

您还将看到文件名旁边有一个文本输入。这与我的问题有关。

下面是框架链接到的 php 脚本videoupload.php,该脚本将上传文件并将数据插入数据库:

     move_uploaded_file($_FILES["fileVideo"]["tmp_name"],
      "VideoFiles/" . $_FILES["fileVideo"]["name"]);
      $result = 1;

    $videosql = "INSERT INTO Video (VideoFile) 
    VALUES (?)";

        if (!$insert = $mysqli->prepare($videosql)) {
      // Handle errors with prepare operation here
    }

            //Dont pass data directly to bind_param store it in a variable
$insert->bind_param("s",$vid);

//Assign the variable
$vid = 'VideoFiles/'.$_FILES['fileVideo']['name'];

 $insert->execute();

        if ($insert->errno) {
          // Handle query error here
        }

        $insert->close();     

?>

 <script language="javascript" type="text/javascript">
 window.top.stopVideoUpload(<?php echo $result; ?>, '<?php echo $_FILES['fileVideo']['name'] ?>');
 </script>  

下面是显示文件插入的示例数据库:

Video_Question 表:

 VideoId (PK auto)  VideoFile
 1                  VideoFiles/carrace.mp4
 2                  VideoFiles/cricket.mov

现在我的问题是,您在 mysqli 代码中看到它将上传的视频文件插入VideoFile数据库中的字段的位置,我如何从VideoId字段中检索值并将其显示在每个相关上传文件的文本输入中?

例如,如果 carrace.mp4 已上传,VideoId则从数据库中检索 1 并将其显示在已上传文件名称旁边的文本输入中。

4

1 回答 1

1

只需在调用$mysqli->insert_id之前调用并将其附加到文件名function stopVideoUpload

$vid需要在绑定之前分配,而不是之后

     $insert->execute();
     $id = $mysqli->insert_id;
        if ($insert->errno) {
          // Handle query error here
        }

        $insert->close();     

?>

 <script language="javascript" type="text/javascript">
 window.top.stopVideoUpload(<?php echo $result; ?>, '<?php echo $id. $_FILES['fileVideo']['name'] ?>');
 </script>  
于 2013-01-18T21:09:33.970 回答