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
htdocsfolder. I named itupload.
- 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
fileat the same directory.
Save all of your changes and type http://localhost/upload/form.php to try upload a file into your directory.
Categories: PHP, Programming, WebDev
form, php, programming, upload







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