drwkqwa82140 2011-04-04 15:47 采纳率: 0%
浏览 17

在下一页中,$ _FILES [“myfile”] [“tmp_name”] = NULL

I had upload file with POST and it seems to works fine, but after I go to the next page I can't use the file with the location in the global varible: $_FILES["myfile"]["tmp_name"] because it's null. I don't know why, I used this code before and it worked fine...

Here is the code:

www/step1.php

if (isset($_POST["check_if_press"]) && $_POST["check_if_press"] == "Upload") 

{

if (!empty($_FILES["myfile"]["tmp_name"])) 

{

  header("Location: ./step2_1.php");

  }else     echo "Please select a file";

}

<form action="<?php echo $PHP_SELF; ?>" method="post" enctype="multipart/form-data">

 Upload file: <input type='file' name='myfile' /><br />

 <input type='Submit' name='check_if_press' value='Upload'  />

</form>

www/step2_1.php

echo  $_FILES["myfile"]["tmp_name"];

Now I get NULL printed on the screen.

When I used POST without the arguments :

action="<?php echo $PHP_SELF

But with:

action="./step2.php"

Instead, It work, but than I cant use the upload check .

Thanks,

Yonatan.

  • 写回答

2条回答 默认 最新

  • duanreng3439 2011-04-04 15:53
    关注

    The file is only present in $_FILES within the scope of the post. What's happening here is:

    1. User is posting a file to step1
    2. step1 is doing something with the file, then telling the user to go to step2 (by means of the location header)
    3. In response to the location header, user is making a GET request to step2, no posted file is associated

    You're going to need to either post the file directly to step2 (which you said worked, just didn't have the logic of step1) and put your server-side file checking logic there, or in step1 store the file somewhere on the server (either save it to the file system, store it in a database, maybe store it in session which I don't recommend, etc.) where it can be accessed by step2.

    step2 is a completely separate request from step1 and doesn't have access to anything within the scope of step1.

    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型