【问题标题】:PHP uploads file - enctype="multipart/form-data" issuePHP 上传文件 - enctype="multipart/form-data" 问题
【发布时间】:2011-02-12 18:45:06
【问题描述】:

我有这个上传代码。单独运行它没有问题,但是当我尝试添加到我的其他代码中时,它没有得到 $_files 参数。我猜这是因为 enctype="multipart/form-data" 在表单标签中,基于这篇文章:

Why File Upload didn't work without enctype?

需要enctype。所以我的问题是,我怎样才能上传文件而不用担心这个? 我们可以更改代码结构,使其与其他代码兼容吗?

  if($_POST['check']){     
    $faillampiran=$_POST['faillampiran'];
    $file=$_FILES['faillampiran']["name"];
    $fileSize = $_FILES['faillampiran']['size'];
    $fileType = $_FILES['faillampiran']['type'];

    if ($_FILES["faillampiran"]["error"] > 0 )
    {
    echo "Return Code: " . $_FILES["faillampiran"]["error"] . "<br />";
    }
    else
    {
    move_uploaded_file($_FILES["faillampiran"]["tmp_name"],"upload/" . $_FILES["faillampiran"]["name"]);
    echo '<table align = "center">';
    echo "<tr><td>";
    echo "Your file has been successfully stored.";
    echo "</td></tr>";
    echo '</table>';
    }   }
 ?>
 <form method="post" name="form1" id="form1" enctype="multipart/form-data">      
    <tr><td></td><td><input type="hidden" name="MAX_FILE_SIZE" value=""> </td> </tr>
    <tr><td> Please choose a file</td><td>:</td></tr>
    <tr>
    <input type="file" size="50" name="faillampiran" alt="faillampiran" id="faillampiran" 1value= "<?=$faillampiran;?>" />
    <tr align = "center"><td colspan = "3"><input type="submit" value="Hantar" name="check"/></td></tr>
    </tr></form> 

谢谢。

【问题讨论】:

  • 您不打算在这些其他表单中添加file 类型的输入字段吗?那么添加 enctype 有什么问题呢?

标签: php


【解决方案1】:

确实必须在表单中包含 enctype,我认为没有任何方法可以解决这个问题,并且有充分的理由。

只需将它也添加到其他表单中,就像您在此处所做的那样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 2010-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多