PHP Upload Single File

April 26, 2010

PHP

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

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:


Subscribe

Subscribe to our e-mail newsletter to receive updates.

12 Responses to “PHP Upload Single File”

  1. Exclusive Tutorials Says:

    Simple and excellent tutorial

    Reply

  2. FAQPAL Says:

    Excellent tutorial, I like the simple ones.

    Reply

  3. nestdev Says:

    Thank’s for sharing !

    Reply

  4. Omer Greenwald Says:

    Great useful tip. Thanks a lot for sharing

    Reply

  5. ultrasound technician Says:

    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!

    Reply

  6. financial aid for college Says:

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

    Reply

  7. CNA License Says:

    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

    Reply

  8. Clara Says:

    Thanks! really useful.

    Reply

  9. tutorial blog Says:

    thank for tutorial

    Reply

  10. limited liability company Says:

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

    Reply

Trackbacks/Pingbacks

  1. uberVU - social comments - April 29, 2010

    Social comments and analytics for this post…

    This post was mentioned on Twitter by tutorialspalace: PHP Upload Single File http://goo.gl/fb/VQVM7

  2. CSS Brigit | PHP Upload Single File - April 29, 2010

    PHP Upload Single File…

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

Leave a Reply

Get Adobe Flash player