我在图像/视频上传php脚本中有一个foreach循环。如果用户同时上传视频和图像,我想在图像上传完成后立即显示响应。(使用dropzone.js并行上传)。我怎么能这样做?下面我给出了一个粗略的代码结构,因为它非常大。
<?php
function getExtension($str)
{
//Function for get extension of upload file array
}
$valid_img_formats = array("jpg", "png", "gif", "bmp","jpeg");
$valid_vid_formats = array("avi", "mp4", "flv", "vob");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{
count=0
foreach ($_FILES['file']['name'] as $name => $value)
{
...
$ext = strtolower($ext);
if(in_array($ext,$valid_img_formats))
{
if ( count( $_FILES['file']['name'] ) == $count )
{
//image moving to filesystem and showing response using database
}
}
elseif(in_array($ext,$valid_vid_formats ))
{
if ( count( $_FILES['file']['name'] ) == $count )
{
//video moving to filesystem and showing response using database
}
}
else
{
echo "invalid file";
}
}
}
?>
我可以使用下面给出的代码获取上传数组中的图像文件数量($ img_count_sum)。我不知道如何使用它并且它有意义吗?
$upload_array = $_FILES['file']['name'];
$img_ext = implode('.', $upload_array);
$img_count_jpg = substr_count($img_ext, 'jpg');
$img_count_jpeg = substr_count($img_ext, 'jpeg');
$img_count_png = substr_count($img_ext, 'png');
$img_count_bmp = substr_count($img_ext, 'bmp');
$img_count_gif = substr_count($img_ext, 'gif');
$img_count_sum_array = array($img_count_jpg,$img_count_jpeg,$img_count_png,$img_count_bmp,$img_count_gif);
$img_count_sum = array_sum($img_count_sum_array);