采取文件上传并转到另一个PHP页面 [英] Take file upload and go to another PHP page

查看:160
本文介绍了采取文件上传并转到另一个PHP页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有4页。他们很简单。
$ b $ index.php(WORKS)

pre $ $ $ $ $ < HTML>
< form action =upload.phpmethod =POSTenctype =multipart / form-data>
< input type =filename =file>< br />
< input type =submitvalue =现在上传!>
< / form>
< / html>

upload.php(WORKS)

<$ p $($ _FILES [file] [error]> 0)
{
echoError:$ p $ <?php
。 $ _FILES [file] [error]。 < br />;
}
else
{
echoUpload:。 $ _FILES [file] [name]。 < br />;
回显类型:。 $ _FILES [file] [type]。 < br />;
回声大小:。 ($ _FILES [file] [size] / 1024)。 Kb< br />;
回声存储在:。 $ _FILES [ 文件] [ tmp_name的值];

echo'你确定要继续保存这个文件';
echo'< a href =yes.php>是,继续< / a>
< br />
< br />
< a href =no.php>不,谢谢< / a>'
}
?>

no.php(WORKS)

 <?php 
echo'Thanks anyway';
?>

yes.php(错误)

<$ p $($ _FILES [file] [error]> 0)
{
echoError:$ p $ <?php
。 $ _FILES [file] [error]。 < br />;
}
else
{
echoUpload:。 $ _FILES [file] [name]。 < br />;
回显类型:。 $ _FILES [file] [type]。 < br />;
回声大小:。 ($ _FILES [file] [size] / 1024)。 Kb< br />;
回声存储在:。 $ _FILES [ 文件] [ tmp_name的值];

echo'我们现在保存这个文件:';
//保存文档代码
}
?>

输出是:

 注意:未定义的索引:第2行的/home/public_html/test/yes.php中的文件无效的文件

现在我们将保存此文档:?

正如你所看到的,我永远不会保存它。但是我想把它保存在 yes.php 页面中。是否仍然可以检索上传的原始文档?提前感谢。
解决方案上传的文件仅适用于单个PHP实例/请求周期。

解决方案

上传的文件存储在临时目录中。如果脚本执行完毕后仍然存在,PHP将会删除它们,假设你不需要它们。

如果你想保存文件,必须在文件上传的相同请求中将其移动到别处。


So I have 4 pages. They are very simple.

index.php (WORKS)

<html>
<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file"><br />
<input type="submit" value="Now upload it!">
</form>
</html>

upload.php (WORKS)

<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  echo "Type: " . $_FILES["file"]["type"] . "<br />";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];

  echo 'Are you sure you want to continue saving this file';
  echo '<a href="yes.php">Yes, continue</a>
  <br />
  <br />
  <a href="no.php">No thanks</a>'
  }
?>

no.php (WORKS)

<?php
echo 'Thanks anyway';
?>

yes.php (ERROR)

<?php
    if ($_FILES["file"]["error"] > 0)
      {
      echo "Error: " . $_FILES["file"]["error"] . "<br />";
      }
    else
      {
      echo "Upload: " . $_FILES["file"]["name"] . "<br />";
      echo "Type: " . $_FILES["file"]["type"] . "<br />";
      echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
      echo "Stored in: " . $_FILES["file"]["tmp_name"];

      echo 'We will now save this document:';
      //Save document code
      }
    ?>

Output of yes:

Notice: Undefined index: file in /home/public_html/test/yes.php on line 2 Invalid file

We will now save this document:?

As you can see I never save it. But I would like to save it in the yes.php page. Is it still possible to retrieve that original doc that was uploaded? Thanks in advance.

解决方案

Uploaded files are only available for a single PHP instance/request cycle.
Uploaded files are stored in the temp directory. If they're still there when the script finishes executing, PHP will delete them assuming you didn't need them.

If you want to persist the file, you'll have to move it elsewhere in the same request that the file was uploaded.

这篇关于采取文件上传并转到另一个PHP页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆