Tuesday, 12 July 2011

PHP Upload single file

PHP Upload single file Simple PHP uploading file scripts.
1. upload.php
2. upload_ac.php

1. Create file upload.php.
2. Create file upload_ac.php.
3. Create folder "upload" for store uploaded files.
Create file upload.php
 <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<form action="upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<td><strong>Single File Upload </strong></td>
<td>Select file
<input name="ufile" type="file" id="ufile" size="50" /></td>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
Create file upload_ac.php
//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif

$path= "upload/".$HTTP_POST_FILES['ufile']['name'];
if($ufile !=none)
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
echo "Successful<BR/>";
//$HTTP_POST_FILES['ufile']['name'] = file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file

echo "File Name :".$HTTP_POST_FILES['ufile']['name']."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>";
echo "<img src=\"$path\" width=\"150\" height=\"150\">";
echo "Error";

No comments:

Post a Comment