How to Upload File on Server in PHP
by TechVidvan Team
Program 1
<html>
<body>
<center>
<pre>
<?php
if(isset($_FILES['myimage']))
{
// $name=$_POST['txtname'];
// $course=$_POST['txtcourse'];
//print_r($_FILES);
$name=$_POST['txtname'];
$course=$_POST['txtcourse'];
$fname=$_FILES['myimage']['name'];
$fsize=$_FILES['myimage']['size'];
$ftempname=$_FILES['myimage']['tmp_name'];
echo " File Name: ".$fname."<br>";
echo " File Size: ".$fsize."<br>";
echo " Temp name: ".$ftempname."<br>";
move_uploaded_file($ftempname,'ImagesData/'.$fname);
echo "Name : ".$name."<br>";
echo "Course : ".$course."<br>";
echo "File Uploaded.......";
}
?>
</pre>
<form method=post enctype="multipart/form-data">
<table border=1>
<tr>
<th>Name</th>
<td><input type=text name=txtname></td>
</tr>
<tr>
<th>Course</th>
<td><input type=text name=txtcourse></td>
</tr>
<tr>
<th>Image</th>
<td><input type=file name=myimage></td>
</tr>
<tr>
<td></td>
<td><input type=submit value=Submit></td>
</tr>
</table>
</form>
</center>
</body>
</html>
Tags: file upload in phphow to upload file on server in phpPHPphp file uploadphp practicalphp programupload file on server in php
TechVidvan Team
TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.