Ajax文件上传脚本会覆盖我的会话变量PHP

时间:2010-01-17 17:12:26

标签: php ajax

以下是我的ajax文件上传器使用的脚本。上传器本身工作正常,但我需要一种方法来存储上传的文件,我正在使用会话变量。问题是如果我每次上传文件时上传多个文件,第一个会话变量都会被覆盖,所以我最终只得到包含数据的$ _SESSION ['hamhamham']。谁能告诉我这里我做错了什么?提前致谢

session_start();

$uploaddir = '../uploads/';
$uploadfile = $uploaddir . date() .time() . basename($_FILES['myfile']['name']);


/* $_SESSION['hamhamham'] = $uploadfile; */

$full = false;

if(isset($_SESSION['hamhamham'])){ 

    if(isset($_SESSION['hohoho'])){ 

        if(isset($_SESSION['workforme'])){ 

            if(isset($_SESSION['sweet'])){ 

                $full = true;

            }else{
                $_SESSION['sweet'] = $uploadfile;
            }

        }else{
            $_SESSION['workforme'] = $uploadfile;
        }

    }else{
        $_SESSION['hohoho'] = $uploadfile;
    }

}else{
    $_SESSION['hamhamham'] = $uploadfile;
}

if($full==false){
    if (move_uploaded_file($_FILES['myfile']['tmp_name'], $uploadfile)) {
      echo "success";
    } else {
      // WARNING! DO NOT USE "FALSE" STRING AS A RESPONSE!
      // Otherwise onSubmit event will not be fired
      echo "error";
    }
}else{
    echo "too many files uploaded";
}

1 个答案:

答案 0 :(得分:2)

制作一个数组

$_SESSION['files'][] = $uploadFile;

访问

foreach($_SESSION['files'] as $file_name)
{
    // do stuff
}