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.

Iklan

One thought on “Create Simple Upload Form with PHP

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

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

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s