Answers for "how to get file from post in php"

PHP
13

basic code for file upload in php

//This is the minimal code for an image upload for first time learners
//html portion
<!DOCTYPE html>
<html>
<head>
	<title>ImageUpload</title>
</head>
<body>
	<form action="upload.php" method="post" enctype="multipart/form-data">
		<label>Username</label>
		<input type="text" name="username">
		<br>
		<label>UploadImage</label>
		<input type="file" name='myfile'>
		<br/>
		<input type="submit" value="upload">
	</form>
</body>
</html>
  
 //php portion
  <?php
	$user=$_POST['username'];
	$image=$_FILES['myfile'];
	echo "Hello $user <br/>";
	echo "File Name<b>::</b> ".$image['name'];

	move_uploaded_file($image['tmp_name'],"photos/".$image['name']);
	//here the "photos" folder is in same folder as the upload.php, 
	//otherwise complete url has to be mentioned
	?>
Posted by: Guest on July-03-2020
0

file get content php post

$postdata = http_build_query(
    array(
        'val1' => 'val1',
        'val2' => 'val2',
    )
);
$url = "your_post_url";

function post($url, $postdata){
    $opts = array('http' =>
        array(
            'method'  => 'POST',
            'header'  => 'Content-Type: application/x-www-form-urlencoded',
            'content' => $postdata
        )
    );
    
    $context  = stream_context_create($opts);
    $result = file_get_contents($url, false, $context);
    return $result;
}

print_r(post($url, $postdata));
Posted by: Guest on February-04-2022

Browse Popular Code Answers by Language