Php上传多个图像以及两个输入文本字段,例如:电子邮件和文件夹名称

时间:2016-07-15 14:49:48

标签: javascript php html

PHP上传多个图像以及两个输入文本字段eg:email,文件夹名称在这里是我的代码,我应该添加代码,我可以沿着电子邮件和文件夹名称发送多个图像:



$max_size = 1024*1024*30; // 30mb
$extensions = array('jpeg', 'jpg', 'png');
$dir = 'http://54.221.28.145:8080/kv_image_rest_service/rest/files/upload';
$count = 0;
if ($_SERVER['REQUEST_METHOD'] == 'POST' and isset($_FILES['files']))
{
    // loop all files
    foreach ( $_FILES['files']['name'] as $i => $name )
    {
        // if file not uploaded then skip it
        if ( !is_uploaded_file($_FILES['files']['tmp_name'][$i]) )
            continue;

        // skip large files
        if ( $_FILES['files']['size'][$i] >= $max_size )
            continue;

        // skip unprotected files
        if( !in_array(pathinfo($name, PATHINFO_EXTENSION), $extensions) )
            continue;

        // now we can move uploaded files
        if( move_uploaded_file($_FILES["files"]["tmp_name"][$i], $dir . $name) )
            $count++;
    }
}

echo json_encode(array('count' => $count));




0 个答案:

没有答案