【问题标题】:how to insert video path, video name in mysql database in php.?如何在php中的mysql数据库中插入视频路径,视频名称。?
【发布时间】:2020-05-29 11:37:22
【问题描述】:

我想在 MySQL 数据库中存储视频路径和名称,但实际上只存储了我在表单中使用的一些字段信息。和视频存储测试上传文件夹

我试过了,但视频路径(位置)和名称没有存储在数据库中。

这是我的代码,

<form id="upload_form" enctype="multipart/form-data" method="post">
<input type="file" name="file1" id="file1"><br><br>
<input type="button" value="Upload File" onclick="uploadFile()">
</form>

控制器:

公共函数 Insert_vedio() {

$vedio_data=array(
 'title'=>$this->input->post('Title'),
 'v_name'=>$this->input->post('fileName'), 
 );
$fileName = $_FILES["file1"]["name"]; // The file name
$fileTmpLoc = $_FILES["file1"]["tmp_name"]; // File in the PHP tmp folder
$fileType = $_FILES["file1"]["type"]; // The type of file it is
$fileSize = $_FILES["file1"]["size"]; // File size in bytes
$fileErrorMsg = $_FILES["file1"]["error"]; // 0 for false... and 1 for true
if (!$fileTmpLoc) { // if file not chosen
    exit();
}
if(move_uploaded_file($fileTmpLoc, "test_uploads/$fileName")){
    echo "$fileName upload is complete";
} else {
    echo "move_uploaded_file function failed";
}

}

【问题讨论】:

  • 那么您当前显示的这段代码的哪一部分应该处理将数据插入数据库?我在这里没有看到 任何东西
  • 您期望从$this-&gt;input-&gt;post('Title')$this-&gt;input-&gt;post('fileName') 得到什么?您显示的表单没有名为Title 的字段,也没有名为fileName 的字段。

标签: php upload


【解决方案1】:

实际上我没有在视图部分提到标题和名称。这是我的实际代码。 name 是视频文件名,但不明白如何给视频名称。

<form id="upload_form" enctype="multipart/form-data" method="post">
<div class="form-group">
     <label for="e1"> Title</label>
     <input type="text" placeholder="Movie Tile" name="Title" id="e1" class="form-control">

     <input type="file" name="file1" id="file1"><br><br>
     <input type="button" value="Upload File" onclick="uploadFile()">
     <progress id="progressBar" value="0" max="100" style="width:300px;"></progress>
     <h6 id="status" style="color:red"></h6> 
     <p id="loaded_n_total"></p>

    <div class="osahan-area text-center mt-3">
        <button class="btn btn-outline-primary">Save Changes</button>
    </div>
  </div>
</form>

【讨论】:

    【解决方案2】:

    这里是我的 Javascript

    <script>
    function _(el)
    {
        return document.getElementById(el);
    }
    function uploadFile(){
        var file = _("file1").files[0];
    
        if(typeof file === "undefined") {
    
            _("status").innerHTML = "ERROR: Please browse for a file before clicking the upload button";
            _("progressBar").value = 0;
            return;
        }
    
        $.get('Upload_vedio/Insert_vedio?getsize', function(sizelimit) {
            if(file.type !== "video/mp4") {
                var typewarn = "ERROR: You have to select a MP4-File";
                _("status").innerHTML = typewarn;
                _("progressBar").value = 0;
                return;
            }
            if(sizelimit < file.size) {
                var sizewarn = "ERROR: The File is too big! The maximum file size is ";
                sizewarn += sizelimit/(1024*1024);
                sizewarn += "MB";
                _("status").innerHTML = sizewarn;
                _("progressBar").value = 0;
                return;
            }
            var formdata = new FormData();
                formdata.append("file1", file);
                formdata.append("size", file.size);
                var ajax = new XMLHttpRequest();
                ajax.upload.addEventListener("progress", progressHandler, false);
                ajax.addEventListener("load", completeHandler, false);
                ajax.addEventListener("error", errorHandler, false);
                ajax.addEventListener("abort", abortHandler, false);
                ajax.open("POST", "Upload_vedio/Insert_vedio");
                ajax.send(formdata);
        });
    }
    function progressHandler(event){
        _("loaded_n_total").innerHTML = "Uploaded "+event.loaded+" bytes of "+event.total;
        var percent = (event.loaded / event.total) * 100;
        _("progressBar").value = Math.round(percent);
        _("status").innerHTML = Math.round(percent)+"% uploaded... please wait";
    }
    function completeHandler(event){
        _("status").innerHTML = event.target.responseText;
        _("progressBar").value = 0;
    }
    function errorHandler(event){
        _("status").innerHTML = "Upload Failed";
    }
    function abortHandler(event){
        _("status").innerHTML = "Upload Aborted";
    }
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 2018-08-15
      • 1970-01-01
      • 1970-01-01
      • 2015-04-17
      • 2020-05-30
      • 2018-09-26
      相关资源
      最近更新 更多