我如何使用PHP从我的iPhone上传视频
问题描述:
I want the user to be able to upload video files to my site from iPhone.
my PHP is here:
<?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")
)
The code is work with all extensions except iPhone extension "mov". Thanks for help :)
我希望用户能够从iPhone上传视频文件到我的网站。 p> \ n
我的PHP在这里: p>
&lt;?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&lt; $ length; $ i ++){
$ randomString。= $ characters [rand(0,$ charactersLength - 1)];
}
返回 $ randomString;
}
$ name_file = name_file();
// END RANDOM代码
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”)
)
code> pre>
该代码适用于除iPhone以外的所有扩展程序 扩展名“mov”。
感谢您的帮助:) p>
div>
答
As documented in Apples developer documentation the MIME type (what PHP calls $_FILES["file"]["type"]
) is video/quicktime
.