【问题标题】:PHP File Upload form doesn't work while uploading video file上传视频文件时PHP文件上传表单不起作用
【发布时间】:2016-11-09 08:36:08
【问题描述】:
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    if($imageFileType != "mp4" && $imageFileType != "avi" && $imageFileType != "mov" && $imageFileType != "3gp" && $imageFileType != "mpeg"){
    echo "File is not an image.";
        $uploadOk = 0;
    } else {
         echo "File is an image ";
        $uploadOk = 1;
    }
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.1";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
?>

似乎一切都写得很好,但脚本没有按应有的方式工作。尝试上传 mp4、mpeg 和所有其他格式。它上传jpeg,torrent文件但拒绝上传视频文件,这是为什么?我在 Windows 上运行 XAMP。问题出在哪里?

【问题讨论】:

  • 这可能是php中max_size_upload限制的问题,默认是2MB
  • 请注意,使用pathinfo() 来确定文件的类型是非常有问题的。它做字符串操作,不分析文件实际包含什么类型的数据。

标签: php forms upload


【解决方案1】:

自己找到答案,需要编辑php.ini文件:

; Maximum allowed size for uploaded files.
upload_max_filesize = 40M

; Must be greater than or equal to upload_max_filesize
post_max_size = 40M

【讨论】:

    猜你喜欢
    • 2017-03-09
    • 2011-09-05
    • 1970-01-01
    • 1970-01-01
    • 2015-02-11
    • 2017-08-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多