Get方法获取POST方法不能获取的字段值?(PHP)


Get method fetches the field value where POST method cant? (PHP)

我有一个带有POST方法的表单,比如

<form name="imgbnk" action="imgbnk.php" method="POST" enctype="multipart/form-data" onsubmit="return validateForm()">
select the image <input type="file" name="imgloc">

其中在imgbnk.php中,am将它们检索为$filename=$_POST["imgloc"];

问题是

  1. 当我使用POST方法时,$filename没有从表单imgbnk中获得任何值,就像我使用GET方法一样,$filename正在返回预期的文件名,我想知道为什么POST不能检索到相同的文件名
  2. 当使用GET方法时,$size=getimagesize($filename);会出现类似于
    Warning: getimagesize(Hydrangeas.jpg) [function.getimagesize]: failed to open stream: No such file or directory in C:'wamp'www'imgbnk'imgbnk.php的警告
  3. 如果我用POST,它的意思是Warning: getimagesize() [function.getimagesize]: Filename cannot be empty

请帮助我理解为什么会发生这种情况,任务是获取图像的完整属性并将其存储在本地。

提前感谢:)

您必须使用POST上传文件。然后使用$_FILES访问上载文件的属性,而不是$_POST。

有关更多详细信息,请参阅本手册条目:http://php.net/manual/en/features.file-upload.php

您可以使用$_FILES来代替$_POST。将获得文件的所有属性$_POST无法用于此文件上传

我建议你这样做

使用检索图像属性

$name=$_FILES['imgloc']['name'];
$size=$_FILES['imgloc']['size'];
$type=$_FILES['imgloc']['type'];
$tmp_path=$_FILES['imgloc']['tmp_name'];
$error=$_FILES['imgloc']['error'];

以及使用检索其他表单字段详细信息

$title=$_POST['title'];
$description=$_POST['desc'];
$keywords=$_POST['keywords'];
$catagiri=$_POST['catagiri'];

您可以在$_FILES['imgloc']['name']中获取文件名。。。