在php中需要有关文件发布变量的帮助。

时间:2011-08-05 02:25:39

标签: php variables file-upload

嘿伙计们,我有两个脚本用于文件上传。

一个是亚马逊s3上传脚本。使用此脚本我可以从计算机上传。另一个是普通的远程上传脚本。

我想在亚马逊s3中实现远程上传功能。

这是我在“直接上传脚本”中的代码。

Html代码

h1>Upload a file</h1>
<p>Please select a file by clicking the 'Browse' button and press 'Upload' to start uploading your file.</p>
    <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
      <input name="theFile" type="file" />
      <input name="Submit" type="submit" value="Upload">
    </form>

用于检索变量的PHP代码

$fileName = $_FILES['theFile']['name'];
$fileTempName = $_FILES['theFile']['tmp_name'];

我的远程上传脚本代码如下。

<form method="POST" action="<?=$self?>">
<input type="text" name="file[]"  size="45" value="">
<input name="submit" type="submit" id="submit" value="submit"></p>
</form>

php代码接收文件

$files = $_POST['file'];

这是我的问题。如何转换我的远程上传代码

  

$ files = $ _POST ['file'];

进入

  

$ fileName = $ _FILES ['theFile'] ['name'];       $ fileTempName = $ _FILES ['theFile'] ['tmp_name'];

希望你们明白我的观点。感谢

1 个答案:

答案 0 :(得分:0)

您必须在enctype代码上设置<form>参数:

<form enctype="multipart/form-data" action="__URL__" method="POST">

PHP手册中提供了更多帮助:http://www.php.net/manual/en/features.file-upload.post-method.php

具体见第二个例子。