PHP Upload Single File

Posted April 26th, 2010 by

This is a simple PHP uploading file tutorial. You can upload files on your server through this script.

Helpful Links


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

single file upload PHP Upload Single File

|—|——————— code ——————–|—|

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"><br>
  <tr><br>
  <form action="upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1"><br>
  <td><br>
  <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"><br>
  <tr><br>
  <td><strong>Single File Upload </strong></td><br>
  </tr><br>
  <tr><br>
  <td>Select file <br>
  <input name="ufile" type="file" id="ufile" size="50" /></td><br>
  </tr><br>
  <tr><br>
  <td align="center"><input type="submit" name="Submit" value="Upload" /></td><br>
  </tr><br>
  </table><br>
  </td><br>
  </form><br>
  </tr><br>
  </table></p>

Step2:

Create file upload_ac.php

|—|——————— code ——————–|—|

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<p><?php<br>
//set where you want to store files<br>
//in this example we keep file in folder upload <br>
//$HTTP_POST_FILES['ufile']['name']; = upload file name<br>
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif<br>
  $path= "upload/".$HTTP_POST_FILES['ufile']['name'];<br>
  if($ufile !=none)<br>
  {<br>
  if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))<br>
  {<br>
  echo "Successful<BR/>"; </p>
<p>//$HTTP_POST_FILES['ufile']['name'] = file name<br>
//$HTTP_POST_FILES['ufile']['size'] = file size<br>
//$HTTP_POST_FILES['ufile']['type'] = type of file<br>
  echo "File Name :".$HTTP_POST_FILES['ufile']['name']."<BR/>"; <br>
  echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>"; <br>
  echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>"; <br>
  echo "<img src=\"$path\" width=\"150\" height=\"150\">";<br>
  }<br>
  else<br>
  {<br>
  echo "Error";<br>
  }<br>
  }<br>
  ?></p>

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

rfp PHP Upload Single File



Related Articles

Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic, or follow us on Twitter. Get promotion with Hypesol.
Name: Email:
12 ResponsesLeave a comment
  • Exclusive Tutorials
    April 28, 2010 at 7:39 am
    Reply

    Simple and excellent tutorial

  • FAQPAL
    April 29, 2010 at 8:04 am
    Reply

    Excellent tutorial, I like the simple ones.

  • nestdev
    April 29, 2010 at 9:00 am
    Reply

    Thank’s for sharing !

  • Omer Greenwald
    April 30, 2010 at 4:53 am
    Reply

    Great useful tip. Thanks a lot for sharing

  • ultrasound technician
    May 2, 2010 at 9:48 pm
    Reply

    Terrific 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!

  • financial aid for college
    June 3, 2010 at 7:24 pm
    Reply

    Great information! I’ve been looking for something like this for a while now. Thanks!

  • CNA License
    June 21, 2010 at 2:04 am
    Reply

    found 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

  • Clara
    July 16, 2010 at 12:57 am
    Reply

    Thanks! really useful.

  • tutorial blog
    August 2, 2010 at 8:41 pm
    Reply

    thank for tutorial

  • limited liability company
    December 22, 2010 at 11:07 am
    Reply

    Nice site, nice and easy on the eyes and great content too.

Add a commentGet a Gravatar

* Name

* Email Address

Website Address

You can usethese tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



  •  
  •  
  •  
Around The Site
Free Subscription

Enter your email address:

 
Become Facebook Fan
Links
Get Adobe Flash playerPlugin by wpburn.com wordpress themes