douzhi2760 2013-10-29 05:15
浏览 30

使用SESSION数组而不是$ _FILES上传文件?

The question is: Is there is any way to make it work with SESSION array ?

Because i have assigned $_FILES["file"] to a SESSION array, it would not upload a file. When i use var_dump($_SESSION['test'][1]["tmp_name"]) and var_dump($_FILES["file"]["tmp_name"]) it would show the same value. any idea guys ?

//THIS WONT WORK
    $_SESSION['file'][] = $_FILES["file"];
    $_SESSION['file'][] = $_FILES["file2"];
    foreach($_SESSION['file'] as $index => $name){
       move_uploaded_file($_SESSION['file'][$index]["tmp_name"], "images/" . $rename);
    }
//THIS WORKS OK
    move_uploaded_file($_FILES["file"]["tmp_name"],
    "images/" . $rename);

Ok now few words why i need to use session ... I need to use session because i have multiple files that i want to upload through foreach statement.

// print_r($_SESSION["file"]) would output:

array(1) {
  [0]=>
  array(5) {
    ["name"]=>
    string(8) "face.jpg"
    ["type"]=>
    string(10) "image/jpeg"
    ["tmp_name"]=>
    string(31) "C:\EasyPHP-12.1\tmp\php882C.tmp"
    ["error"]=>
    int(0)
    ["size"]=>
    int(22398)
  }
}
  • 写回答

2条回答 默认 最新

  • dosryjij88555 2013-10-29 05:33
    关注
    1. You must save your file using move_uploaded file

    2. Check whether $_SESSION["test"] exists. If not, create it, $_SESSION["test"] = array();

    3. $_SESSION["test"][] = "images/" . $rename;

    4. You can reach the last uploaded file with $_SESSION["test"][count($_SESSION["test"] - 1]. If you uploaded a single file, then it is incorrect to reference to it with $_SESSION["test"][1].

    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)