Php 逐个上传多个视频
有人能帮我上传多个静态名称的视频吗?我想一个接一个地上传多个视频,这意味着用户是否可以上传任何类型的视频Php 逐个上传多个视频,php,Php,有人能帮我上传多个静态名称的视频吗?我想一个接一个地上传多个视频,这意味着用户是否可以上传任何类型的视频 <form action="" method="post" enctype="multipart/form-data"> <input name="vv" type="file" id="file"/> <input type="submit" value="UPLOAD" name="submit" id="upload" style="
<form action="" method="post" enctype="multipart/form-data">
<input name="vv" type="file" id="file"/>
<input type="submit" value="UPLOAD" name="submit" id="upload" style=" background:#03d5fb; color:#00264a; font-size:26px; margin-top:4%; width:23%;" />
</form>
<?php
$resultt=(mysql_query("Select * From aa where email ='$_SESSION[login_user]'"));
$rows= (mysql_fetch_array($resultt, MYSQL_ASSOC));
$id=$rows['id'];
if (isset($_POST['submit'])) {
if(!is_dir("images/videos".$id.'/')) {
mkdir("images/videos".$id.'/');
$filess = $_FILES['vv']['name'];
$tmppath = $filess ['tmp_name'];
$target_dir = "images/videos".$id.'/';
$random=rand(0000, 9999);
move_uploaded_file($tmppath, $target_dir.'video'.$random.'.mp4');
echo "uploaded ";
}
else
{
$filess = $_FILES['vv']['name'];
$tmppath = $filess ['tmp_name'];
$target_dir = "images/videos".$id.'/';
$random=rand(0000, 9999);
move_uploaded_file($tmppath, $target_dir.'video'.$random.'.mp4');
echo "uploaded ";
}
}
?>
为了允许用户选择和上传多个文件,下面是一些简单的代码提示
- 输入名称必须定义为数组,即
name=“inputName[]”
- 输入元素必须具有
multiple=“multiple”
或只是multiple
。了解
更多信息,请查看
- 在PHP文件中使用以下语法
$\u文件['inputElemName']['param'][index]
现在让我们来看看你的代码
HTML
<form action="" method="post" enctype="multipart/form-data">
<input type="file" id="file" name="file[]" multiple="multiple"/>
<input type="submit" value="UPLOAD" name="submit" id="upload" style=" background:#03d5fb; color:#00264a; font-size:26px; margin-top:4%; width:23%;" />
</form>
PHP
<?php
if (isset($_POST['submit']))
{
$result = mysql_query("Select * From aa where email = '".$_SESSION[login_user]."'");
if($result)
{
$row = mysql_fetch_array($result);
$id = $row['id'];
if(!is_dir("images/videos".$id.'/'))
{
mkdir("images/videos".$id.'/');
}
$target_dir = "images/videos".$id;
// setup an array to check errors at the time of file upload
$errors = array();
//Loop through each file
for($i=0; $i<count($_FILES['file']['name']); $i++)
{
// set the array of allowed extensions
$allowed = array('mp4', 'mkv');
// extrach the file extension and check if it is valid
$ext = pathinfo($_FILES['file']['name'][$i], PATHINFO_EXTENSION);
if(!in_array($ext,$allowed))
{
$errors[] = "Invalid fiel extension.";
}
if(empty($errors))
{
// make parts of file name to append timestamp to them to avoid uploading of files with same name
$path_parts = pathinfo($_FILES["file"]["name"][$i]);
$image_path = $path_parts['filename'].'_'.time().'.'.$path_parts['extension'];
//Setup our new file path
$newFilePath = $target_dir.'/'.$image_path;
//Upload the file into the temp dir
if(move_uploaded_file($_FILES["file"]["tmp_name"][$i], $newFilePath))
{
//Handle other code here
}
}
else
{
print_r($errors);
}
}
if(empty($errors))
{
echo "Success";
}
}
else
{
echo "Error while fetching records ".mysql_error();
}
}
?>
试试dropjone.js
它会对你有所帮助。不,这不是我要找的。谢谢