PHP File Upload to Temporary Folder Code

In this tutorial we are going to follow the steps -

1. Create send.php with upload form and button.
2. Display the content of uploaded file.

Take a look at the gist below. If it is not visible then you can go this link.

https://gist.github.com/codesynapse/6082642


<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>File Upload Example</title>
</head>
<body>
<form method="post" action="upload.php" enctype="multipart/form-data">
<label> Upload your file</label><br/>
<input type="file" name="file" id="file"><br/>
<input type="submit" name="submit">
</form>
</body>
</html>
view raw send.php hosted with ❤ by GitHub
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>File Upload Status</title>
</head>
<body>
<?php
//by using $_files array you can store data from client computer to the remote server
//check if the file is uploaded, if not then pass the error
if($_FILES['file']['error']>0) {
echo 'Error :'.$_FILES['file']['error']."<br/>";
}
//if the file is uploaded successfully, echo the file size, type and location
echo "Upload ". $_FILES['file']['name']."<br/>";
echo "Type ". $_FILES['file']['type']."<br/>";
echo "Size ".($_FILES['file']['size']/1024) ."<br/>";
echo "Stored in :".$_FILES['file']['tmp_name']."<br/>";
?>
</body>
</html>
view raw upload.php hosted with ❤ by GitHub