javascript - How do I translate a html form post request into Postman - Stack Overflow

So I got this simple HTML form<form action="upload.php" method="post" enctype=&q

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
Add a ment  | 

1 Answer 1

Reset to default 5

Open 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745221339a4617262.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信