Friday 29 June 2012

Code To Upload A File Using PHP

Step I : First Create a Page In Html For Uploading (Try The Following Code In Order To So)
<html>
<body bgcolor='black'>
<table  align="center">
<tr>
<td>
<form action="fileupload.php" method="post"  enctype="multipart/form-data" >
<font color="#0d8ffe" size="2" ><u>File Upload</u></font>&nbsp;&nbsp;&nbsp;<input name="file" type="file" class="pimg1"  />
 &nbsp;&nbsp;<input type="submit" value="Upload" style="background:#0d8ffe;border:0;"/>
</form>
</td>
</tr>
</table>
</body>
</html>

Step II : Then Use The Following Function To Move The file To Desire Locaton.



<?php 
if(empty($_FILES["file"]["name"]))
{
header("Location:entry.php");
exit;
}
require "comm.php";


$filename = $_FILES["file"]["name"];
               $name=split("\.",$filename);
      $nm = $name[0];
     $ext = $name[1];



move_uploaded_file($_FILES["file"]["tmp_name"],"$nm.$ext");
?>

No comments:

Post a Comment