我如何使用PHP从我的iPhone上传视频

时间:2017-07-04 17:15:40

标签: php file-upload

我希望用户能够通过iPhone将视频文件上传到我的网站。

我的PHP在这里:

 <?php

$allowedExts = array("jpg", "JPG", "jpeg", "JPEG", "gif", "GIF", "png", "PNG", "mp4", "MP4", "mov", "MOV");
$extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);

// RANDOM Code
function name_file($length = 20) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}

$name_file = name_file();
// END RANDOM Code

if ((($_FILES["file"]["type"] == "video/mp4")
|| ($_FILES["file"]["type"] == "video/MP4")
|| ($_FILES["file"]["type"] == "video/mov")
|| ($_FILES["file"]["type"] == "video/MOV")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/JPEG")
|| ($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/GIF")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/PNG")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/JPG")
)

该代码适用于除iPhone扩展名“mov”之外的所有扩展程序。 感谢您的帮助:)

1 个答案:

答案 0 :(得分:1)

Apples developer documentation中所述,MIME类型(PHP调用$_FILES["file"]["type"])是video/quicktime