【问题标题】:How to pass value on the other page using $_FILES如何使用 $_FILES 在其他页面上传递值
【发布时间】:2013-12-04 03:04:39
【问题描述】:

有没有一种方法可以使用 $_FILES 在其他页面上传递价值?

这是我的代码:

test.php

<form id="form" method="post" enctype="multipart/form-data">
<input type="file" name="userfile" id="userfile">
    <input type="submit" id="submit" name="submit" value="Submit">
</form>

提交.php

<?php 
    if (isset( $_SERVER['HTTP_X_REQUESTED_WITH'] )):

        if (!empty($_POST['name']) AND !empty($_POST['email']) AND !empty($_POST['comment'])) {
            $name = $_POST['name'];
            $mail = $_POST['email'];
            $message = $_POST['comment'];
            $ticket_id = $_POST['id'];
            $file = $_FILES['userfiles'];

            $comment->insertMessage($ticket_id,$message,$name);
        } 

        if(!empty($_FILES['userfile'])) {
            $comment->attachFile();
        }
?>
<?php
      endif
?>

如何使用 $_FILES 传递值?

【问题讨论】:

  • 我完全不知道你想问什么。
  • 你想问什么?'
  • 我如何将值从这里 传递到 submit.php 页面
  • 你把你想要表单提交到的页面的URL放在action属性中,然后你点击提交按钮。
  • @user2434677 move_uploaded_file ($_FILES['userfile']['tmp_name'] , $destination)

标签: php html


【解决方案1】:

确保您提交到正确的页面 - 您的表单标签中需要一个操作属性。

<form id="form" action="submit.php" method="post" enctype="multipart/form-data">
<input type="file" name="userfile" id="userfile">
    <input type="submit" id="submit" name="submit" value="Submit">
</form>

【讨论】:

    【解决方案2】:

    使用函数move_uploaded_file将文件保存到所需位置($destination)

    move_uploaded_file ($_FILES['userfile']['tmp_name'] , $destination )
    

    【讨论】:

      【解决方案3】:

      您曾经使用过会话吗?

       $_session['sessionname'] = $variable;  
      

      在下一页。

      $variable =$_session['sessionname'];
      

      【讨论】:

        【解决方案4】:

        使用

        $_FILES['userfiles']['name'];
        $_FILES['userfiles']['tmp_name'];
        

        而不是

         $_FILES['userfiles'];
        

        【讨论】:

        • @user2434677 move_uploaded_file ($_FILES['userfile']['tmp_name'] , $destination)
        猜你喜欢
        • 1970-01-01
        • 2014-08-25
        • 1970-01-01
        • 2016-06-06
        • 2023-03-26
        • 2016-09-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多