Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在php中使用$\u文件上载文件_Php - Fatal编程技术网

无法在php中使用$\u文件上载文件

无法在php中使用$\u文件上载文件,php,Php,我无法使用以下脚本上载文件。 我不知道这有什么问题,或者我必须配置我的php.ini。请帮忙。。。 以下是我的HTML代码: <form method="get" action="review" enctype="multipart/form-data" name="form"> <input type="file" name="attachment" /> </div> <input type="submit" class="button" valu

我无法使用以下脚本上载文件。 我不知道这有什么问题,或者我必须配置我的php.ini。请帮忙。。。 以下是我的HTML代码:

<form method="get" action="review" enctype="multipart/form-data" name="form">
<input type="file" name="attachment" />
</div>

<input type="submit" class="button" value="Upload file" />
</form>
我在/review/index.php上的php脚本是:

if(isset($_GET["attachment"])){
    $file_name = $_FILES["attachment"]['name'];
    $random_digit=rand(0000,9999);
    $new_file_name=$random_digit.$file_name;
    $url="/attachment/".$new_file_name;

if(move_uploaded_file($_FILES['attachment']['tmp_name'], $url)) 
 {
    echo"file uploaded";

    $attachment='<h3>Attachment</h3><img src="/images/glyphicons_062_paperclip.png" />  <a href="/attachment/'.$_GET["attachment"].'">'.$_GET["attachment"].'</a>';
    }
我得到的错误如下:

未定义索引:第13行C:\xampp\htdocs\view question\review answer\index.php中的附件

我不知道我哪里做错了请帮助。。。。 提前感谢…

更换:

<form method="get"
与:


您发送的文件类型字段值在GET请求中不可用

尝试更改第13行:

if(isset($_GET["attachment"])){
为此:

if(isset($_FILES["attachment"])){

Method=GET应替换为POST。GET应该用于从服务器获取信息,并在服务器上发布内容。仅对服务器上没有任何更改的内容使用GET

此外,URL限制在2000个字符左右,因此压缩URL中的文件不是一个好主意。文件也可以使用URL编码,所以不要使用GET。

首先要更改

<form method="get"


您错过了结束日期}是吗?将所有$\u GET更改为$\u POST,文件数据通过POST正文而不是查询字符串发送。谢谢大家,我已将其更改为$POST,现在它正在工作。。
<form method="get"
<form method="post"
$_GET['attachment']
$_POST['attachment']