web 2.0

How to use PHP & File ($_FILES,$HTTP_POST_FILES)

How to use PHP & File ($_FILES,$HTTP_POST_FILES) Learn PHP how to using $_FILES and read a php variable , upload file

ShotDev Focus:
- Using $_FILES for upload file

Example

php_file1.php


<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form action="php_file2.php" method="post" enctype="multipart/form-data" name="form1">
<input type="file" name="fileUpload">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>

php_file2.php


<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<?php
echo "\$_FILES[\"fileUpload\"][\"name\"] = ".$_FILES["fileUpload"]["name"]."<br>";
echo "\$_FILES[\"fileUpload\"][\"type\"] = ".$_FILES["fileUpload"]["type"]."<br>";
echo "\$_FILES[\"fileUpload\"][\"size\"] = ".$_FILES["fileUpload"]["size"]."<br>";
echo "\$_FILES[\"fileUpload\"][\"tmp_name\"] = ".$_FILES["fileUpload"]["tmp_name"]."<br>";
echo "\$_FILES[\"fileUpload\"][\"error\"] = ".$_FILES["fileUpload"]["error"]."<br>";

if(copy($_FILES["fileUpload"]["tmp_name"],"myfile/".$_FILES["fileUpload"]["name"])) // Upload/Copy
{
echo "Copy/Upload Completed.";
}
?>
</body>
</html>

Create a php file and save to path root-path/myphp/

Run
http://localhost/myphp/php_file1.php

Screenshot

PHP Upload file

PHP Upload file

PHP Upload file

PHP Upload file

.
.
.

Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (2 votes, average: 5.50 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.