phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Upload : Simple Upload a File (Part 1)

Tag: upload   Category: PHP Basic
post: 06 Dec 2007 read: 808


Upload file is a facility that almost exists at all administrator web function. This post about how to build form and action uploading a file. Next post, we will discuss about how to upload multi files at a time.

In this practice, we just need 2 file:

- form.php as interface for upload file.
- upload.php as 'engine' for upload file.

Assume, we work within www/test/upload directory in Windows system.

form.php

 <html>
 <head>
 <title>Form Upload a File</title>
 </head>
 <body>
 <form method="post" enctype="multipart/form-data" action="upload.php">
 <input type="file" name="ufile" />
 <br />
 <input type="submit" name="submit" value="Submit" />
 </form>
 </body>
 </html>

Then, we create upload.php.


 <?
 $uploaddir  = "C:\\AppServ\\www\\test\\upload\\";
  •   $uploadfile = $uploaddir. $_FILES['ufile']['name'];
  •   if(move_uploaded_file($_FILES['ufile']['tmp_name'], $uploadfile)){    echo "upload success";  }  ?>
  • If you use different system, you can change line 2 ($uploaddir).

    Point your browser to http://localhost/test/upload/form.php. click browser, and then click Submit.



    Series this article:
    Upload : Simple Upload a File (Part 1)
    Upload File : Upload Multi File (Part 2)

    | Give Your Opinion | Recommend
    Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
    digg del.icio.us technorati Ma.gnolia BlinkList

    Recommended articles by other readers:
    Web Services: How PHP Kiss VB.NET? (Part 1)
    Chart: How to Build Cool Animation Real Time Chart
    Joomla: Fast Road to Understand Component Programming
    Email: Send Attachement Mail
    mod_rewrite - Part 1: create your "fantasy" URL

    What do You Think?
    Your Name *:
    Email *:
    (Will not be published)
    Website/URL:
    Your Comment *:
    * Required


    615
    posting