视频上传PHP脚本不工作

视频上传PHP脚本不工作,php,html,image,video,Php,Html,Image,Video,我想上传视频而不是图像我使用此脚本上传图像,但现在我想上传视频,我已将文件类型更改为视频文件类型,但它不起作用,并向我发出此通知 Notice: Undefined index: file in C:\xampp\htdocs\mysql_login\upload.php on line 26 The file you attempted to upload is not allowed. 这是我的PHP脚本: <?php if(!isset($_COOKIE['loggedin

我想上传视频而不是图像我使用此脚本上传图像,但现在我想上传视频,我已将文件类型更改为视频文件类型,但它不起作用,并向我发出此通知

Notice: Undefined index: file in C:\xampp\htdocs\mysql_login\upload.php on line 26
The file you attempted to upload is not allowed.
这是我的PHP脚本:

<?php
    if(!isset($_COOKIE['loggedin'])){
        header("location:user_login.php");
    }

session_start();

if(!isset($_SESSION['user'])){

header("location: user_login.php");
}
else {

?>

<?php
    include("connection.php");
$current_page_URL =(isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"]==”on”) ? “https://” : “http://”;

$current_page_URL = $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];

$allowed_filetypes = array('.avi','.mp4','.wmv','.flv');
$max_filesize = 104857660;
$upload_path = 'uploads/';

$filename = $_FILES['file']['name'];
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);

if(!in_array($ext,$allowed_filetypes))
  die('The file you attempted to upload is not allowed.');

function bytesToSize1024($bytes, $precision = 2) {
    $unit = array('B','KB','MB');
    return @round($bytes / pow(1024, ($i = floor(log($bytes, 1024)))), $precision).' '.$unit[$i];
}

$sFileName = $_FILES['file']['name'];
$sFileType = $_FILES['file']['type'];
$sFileSize = bytesToSize1024($_FILES['file']['size'], 1);




    if (file_exists("uploads/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "uploads/" . $_FILES["file"]["name"]);
      echo "Stored in: ".$_SERVER["SERVER_NAME"]. "/uploads/" . $_FILES["file"]["name"];

      }
      $savefile = $_SERVER["SERVER_NAME"]. "/uploads/" . $_FILES["file"]["name"];

      $insert_query = "insert into save_data (username, Name, Type, size, link) values ('".$_SESSION['user']."','$sFileName','$sFileType','$sFileSize','$savefile')";

    if(mysql_query($insert_query)){

    echo "<script>alert('Successfully added to DB')</script>";

}}
  ?>

1024 * 1024) {
iSpeed=(Math.round(iDiff*100/(1024*1024))/100.toString()+'MB/s';
}否则如果(iDiff>1024){
iSpeed=(Math.round(iDiff*100/1024)/100.toString()+'KB/s';
}
document.getElementById('speed').innerHTML=iSpeed;
document.getElementById('remaining').innerHTML='|'+secondsToTime(secondsRemaining);
}
函数uploadProgress(e){//正在进行上载进程
if(如长度可计算){
iBytesUploaded=e.loaded;
iBytesTotal=e.总计;
var iPercentComplete=数学整轮(e.loaded*100/e.total);
var iBytesTransfered=bytesToSize(ibytesupload);
document.getElementById('progress_percent')。innerHTML=iPercentComplete.toString()+'%';
document.getElementById('progress').style.width=(iPercentComplete*4.toString()+'px';
document.getElementById('b_transfered')。innerHTML=iBytesTransfered;
如果(iPercentComplete==100){
var ouploadsresponse=document.getElementById('upload_response');
oUploadResponse.innerHTML='请稍候…处理';
oUploadResponse.style.display='block';
}
}否则{
document.getElementById('progress').innerHTML='无法计算';
}
}
函数uploadFinish(e){//上载成功完成
var ouploadsresponse=document.getElementById('upload_response');
oUploadResponse.innerHTML=e.target.responseText;
oUploadResponse.style.display='block';
document.getElementById('progress_percent')。innerHTML='100%';
document.getElementById('progress').style.width='400px';
document.getElementById('filesize')。innerHTML=sResultFileSize;
document.getElementById('remaining').innerHTML=''00:00:00';
间隔时间;
}
函数上传错误(e){//上传错误
document.getElementById('error2').style.display='block';
间隔时间;
}  
函数uploadAbort(e){//upload abort
document.getElementById('abort').style.display='block';
间隔时间;
}
HTML文件

<!DOCTYPE html>
<html lang="en" >
    <head>
        <meta charset="utf-8" />
        <title>Pure HTML5 file upload | Script Tutorials</title>
        <link href="css/main.css" rel="stylesheet" type="text/css" />
        <script src="js/script.js"></script>
    </head>
    <body>
    <div class="container">
      <div class="contr"><h2>You can select the file (image) and click Upload button</h2></div>

            <div class="upload_form_cont">
                <form id="upload_form" enctype="multipart/form-data" method="post" action="upload.php">
                    <div>
                        <div><label for="file">Please select image file</label></div>
                        <div><input type="file" name="file" id="file" onchange="fileSelected();" /></div>
                    </div>
                    <div>
                        <input type="button" value="Upload" onclick="startUploading()" />
                    </div>
                    <div id="fileinfo">
                        <div id="filename"></div>
                        <div id="filesize"></div>
                        <div id="filetype"></div>
                        <div id="filedim"></div>
                    </div>
                    <div id="error">You should select valid image files only!</div>
                    <div id="error2">An error occurred while uploading the file</div>
                    <div id="abort">The upload has been canceled by the user or the browser dropped the connection</div>
                    <div id="warnsize">Your file is very big. We can't accept it. Please select more small file</div>

                    <div id="progress_info">
                        <div id="progress"></div>
                        <div id="progress_percent">&nbsp;</div>
                        <div class="clear_both"></div>
                        <div>
                            <div id="speed">&nbsp;</div>
                            <div id="remaining">&nbsp;</div>
                            <div id="b_transfered">&nbsp;</div>
                            <div class="clear_both"></div>
                        </div>
                        <div id="upload_response"></div>
                    </div>
                    <div>


                    </div>
                </form>

                <img id="preview" />
            </div>
        </div>
    </body>
</html>

纯HTML5文件上传|脚本教程
您可以选择文件(图像)并单击上载按钮
请选择图像文件
您应该只选择有效的图像文件!
上载文件时出错
用户已取消上载,或浏览器已断开连接
你的档案很大。我们不能接受。请选择更多的小文件

检查正在上载的文件的扩展名
所以,就这么做吧


 echo $ext;
查看它是否与数组中的值匹配。很可能不是这样




希望这有帮助。

现在它说的是
警告:in_array()希望参数2是数组,布尔值在C:\xampp\htdocs\mysql_login\upload.php第29行中给出,您试图上传的文件是不允许的。
@跪在ZODNot之前,仍然不会得到相同的通知回显扩展名,看看它是否与数组中的值匹配。这应该告诉你问题出在哪里。是的,我也这么做了,但现在不行了。我用了另一个脚本,效果很好。顺便说一句,感谢您的帮助。有一件事:“上的这些卷曲引号将杀死您的代码。

 echo $ext;