我一直在尝试上传多个文件

时间:2013-11-28 14:39:38

标签: php

我一直在尝试上传多个文件并移动到不同的文件夹,文件上传和移动但格式为.tmp所以,如何更改?

$tree3=getcwd();

echo $tree3;

foreach ($_FILES['file']['tmp_name'] as $filename)
{
    foreach ($_FILES['file']['name'] as $filename2)
    {
        move_uploaded_file($filename, $tree3.'/'.basename($filename));
    }
}

1 个答案:

答案 0 :(得分:0)

试试这个 -

<?php
$uploads_dir = '/uploads';
foreach ($_FILES["file"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["file"]["tmp_name"][$key];
        $name = $_FILES["file"]["name"][$key];
        move_uploaded_file($tmp_name, "$uploads_dir/$name");
    }
}
?>

了解更多信息:http://us1.php.net/move_uploaded_file