admin管理员组文章数量:1415111
So I got this simple HTML form
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
So I got this simple HTML form
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
Which looks like this
This allows me to upload an image and post it to the server where is it handled by the "upload.php" script.
upload.php
looks like this
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
I would like to use Postman to send these post requests manually, but I don't how to make a proper request in postman.
So far I have tried like this
But the PHP script doesn't recognise $_FILES["fileToUpload"]
I hope someone can tell/explain to me how I can use Postman
so send a post request that can be handled by this PHP script.
If it's possible to do exactly this but then in JavaScript, I would love to know.
Have a great weekend :)
Share Improve this question edited Oct 18, 2020 at 17:19 Mootje 3292 silver badges12 bronze badges asked Oct 18, 2020 at 17:03 pluto9800pluto9800 2873 silver badges14 bronze badges 1- I think looking at this stackoverflow./questions/39037049/… will be helpful. It describes doing POST request with postman including files. – Tom Groot Commented Oct 18, 2020 at 17:38
1 Answer
Reset to default 5Open your form on the browser (Chrome or Firefox).
Open the dev tools (F12) and go to the network tab.
Submit your form. You should see your request in the network tab.
Do a right click on the request and select Copy/ Copy as cURL (bash)
Open Postman, click Import
, select Raw text
and paste what is in the clipboard from copying from Chrome.
Click Continue
, and in Postman you will have the request.
本文标签: javascriptHow do I translate a html form post request into PostmanStack Overflow
版权声明:本文标题:javascript - How do I translate a html form post request into Postman - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745221338a2648408.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论