Home > database >  Image file upload php (post request)
Image file upload php (post request)

Time:11-24

Can someoen help me with a problem?

I need a html site where i can upload a picture ( only jpg jpeg and png are allowed) I then need to output the size and name of the file in Json.

i have tried nothing because i understand nothing

CodePudding user response:

This can be a simple example:

<form method="post" enctype="multipart/form-data" role="form">
    <input type="file" id="file" name="file" accept=".jpg, .jpeg, .png">
    <input type="submit" name="submit" value="Submit Form">
</form>

<?php
if(isset($_POST['submit'])){
   $json = '{"name": "'.$_FILES['file']['name'].'", "size": "'.$_FILES['file']['size'].'"}';
   echo json_encode($json);
}
?>

You can find documentantion about $_FILES here: documentation

  • Related