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.