Beranda > PHP, Programming, WebDev > Create Simple Upload Form with PHP

Create Simple Upload Form with PHP

Last week, I have a task to create upload system from my friend. I gave her a simple form to upload file to her web directory. It works to get selected file from your computer and try to upload it to your web directory. I used XAMPP for this project before make it online.

  • create new directory in htdocs folder. I named it upload.
  • Open that directory and create new file called “form.php”. Insert code above inside form.php

<html>
 <body><h1>Test upload and listing directories</h1>

<form enctype="multipart/form-data" action="upload.php" method="POST">
 Pilih file:
 <input name="uploaded" type="file" /><br />
 <input type="submit" name="upload" value="Upload" />
 </form>
 </body>

</html>

  • Now, create new file called “upload.php”. This file contains code to upload a file to web server.

<?php
if(isset($_POST['upload'])){
$target = "file/";
$target = $target . basename($_FILES['uploaded']['name']);
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename($_FILES['uploadedfile']['name']). "has been uploaded";
}
else{
echo "Data gagal disimpan.";
}</code>
}

?>

  • Last step, create new folder called file at the same directory.

Save all of your changes and type http://localhost/upload/form.php to try upload a file into your directory.

  1. 10 Desember 2010 pada 6:08 am | #1

    I try to learn about PHP,and i think is wonderful program to build a great website

  1. Belum ada trackback.

Tinggalkan Balasan

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Ubah )

Twitter picture

You are commenting using your Twitter account. Log Out / Ubah )

Facebook photo

You are commenting using your Facebook account. Log Out / Ubah )

Connecting to %s

Ikuti

Get every new post delivered to your Inbox.