Like Us Like Us Facebook Subscribe Subscribe us YouTube Whatsapp Share us Whatsapp Query Send your queries

PHP File Uploading tutorial with example

PHP File Uploading tutorial with example

In this tutorial I am going to demonstrate how to upload a file (like images, word and PDF documents, videos, ZIP) using PHP to server.

Create a directory “uploads” in your project directory.
Upload.php

<! DOCTYPE html>
<html>
<body>
<head>
<meta charset=”utf-8″/>
<title>PHP File Upload</title>
</head>

<?php
$path=”uploads/”;
$path=$path.$_FILES[‘file_upload’][‘name’];
if(isset($_POST[‘upload’]))
{
if(move_uploaded_file($_FILES[‘file_upload’][‘tmp_name’],$path))
{
echo “The file “.basename($_FILES[‘file_upload’][‘name’]).” has been uploaded”;
}
else
{
echo “There is an error,please retry or ckeck path”;
}
}
?>

<form action=”” method=”post” enctype=”multipart/form-data”>
<table width=”384″ border=”1″ align=”center”>
<tr>
<td width=”108″>Select File</td>
<td width=”260″><label>
<input type=”file” name=”file_upload”>
</label></td>
</tr>
<tr>
<td><label>
<input type=”submit” name=”upload” value=”Upload File”>
</label></td>
<td>&nbsp;</td>
</tr>
</table>
</form>

</body></html>

In Upcoming tutorial we will learn how to upload only images, images with particular size, PDF, DOC, exel file, how to compress images and upload to server.

2
Leave a Reply

avatar
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
Learn DigitalShreyaz Recent comment authors

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
newest oldest most voted
Notify of
Shreyaz
Guest

I don’t have an idea how to create website . after read this post i have more then idea about create website. So,thanks for sharing and keep update regularly.

Learn Digital
Guest

Very useful and informative content has been shared out here, Thanks for sharing it.
Visit Learn Digital Academy for more information on Digital marketing course in Bangalore.

Do you have any Query / Suggestion