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
.
.
.