This is a simple PHP uploading file tutorial. You can upload files on your server through this script.
Overview
In this tutorial create 2 files
1. upload.php
2. upload_ac.php
Step
1. Create file upload.php.
2. Create file upload_ac.php.
3. Create folder "upload" for store uploaded files.
4. CHMOD your upload folder to "777" by using your ftp software(change permission).
Step1:
Create file upload.php
|---|--------------------- code --------------------|---|
{code type=codetype}
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>Single File Upload </strong></td>
</tr>
<tr>
<td>Select file
<input name="ufile" type="file" id="ufile" size="50" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
{/code}
Step2:
Create file upload_ac.php
|---|--------------------- code --------------------|---|
{code type=codetype}
<?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\">";
}
else
{
echo "Error";
}
}
?>
{/code}
Step3:
CHMOD upload folder to 777 (change permission)
This step, do it when you upload to real server. This example, I use CuteFTP, right click at upload folder > FTP Commands > CHMOD
Simple and excellent tutorial
ReplyDeleteExcellent tutorial, I like the simple ones.
ReplyDeleteThank's for sharing !
ReplyDeleteGreat useful tip. Thanks a lot for sharing
ReplyDeleteTerrific work! This is the type of information that should be shared around the web. Shame on the search engines for not positioning this post higher!
ReplyDeleteGreat information! I’ve been looking for something like this for a while now. Thanks!
ReplyDeletefound your site on del.icio.us today and really liked it.. i bookmarked it and will be back to check it out some more later
ReplyDeleteThanks! really useful.
ReplyDeletethank for tutorial
ReplyDeleteNice site, nice and easy on the eyes and great content too.
ReplyDelete