arrow left
arrow right
Electronic Products Catelogue JHV Booth Online WEBSITE DESIGNING COMPANY IN INDIA Video Production and DVD Filming Professional Community Portal Surgical Instruments Exporters Job Search Discussion Forum NGO in India online Website Translators Car Hire Company India Manufacturer of automotive bearings Bikini Selling Online Movers and Packers Directory Indian B2B Directory Automotive PR agency Freelance Automotive Journalism Engineering Works India Music libraries online Professional Business Services online tour operator of India Online Property Furnishing Services Indian php programming firm Tour and Travel Directory Luxury Tailored Coats STRANCO ABITA SPRINGS Indian Tour Operator Truck Transport India Maithili Society and Culture World of RS Furniture  B2B Trade Directory office jobs delhi

How to upload files in php

This articles teaches us how to upload files in php programming.

Software >> PHP Programming

Overview: In this article we will show you how simple it is to upload File from the browser.

Uploading a file is a very simple process, To upload a file to a Web server via an HTML form interface, we will be performing the following tasks.

First we create a HTML form (upload_form.htm)

Create an PHP script (upload_file.php) that actually uploads the file!

Creating the HTML Upload form

upload_form.htm

<html>
<head>
<title>Upload a File</title>
</head>
<body>
<font face=verdana size=2>
<B>Upload a File</B>

<form enctype="multipart/form-data" method="post" action="upload_file.php">
<input type="hidden" name="MAX_FILE_SIZE" value="25000">

<p><strong>File to Upload:</strong><br>
<input type="file" name="our_file" size="30"></p>

<P><input type="submit" name="submit" value="Upload File"></p>

</form>
</font></body>
</html>

Note that in the form tag we use the enctype="multipart/form-data" attribute so that the browser knows that more than just text variables are coming at it.

We also have a hidden feild with the name name="MAX_FILE_SIZE" which set's the maximum file size in bytes that can be uploaded.


Now that we have the HTML form we create upload_file.php which actually uploads the file.
upload_file.php 

<?
 if ($our_file != "") {
 
 copy($our_file, "upload/$our_file_name") or die("Couldn't Upload the file!"); 
 
} else {
 
 die("No input file specified");
}

?>

<html>
<head>
<title>Successful File Upload!</title>
<body><font face=verdana size=2>

<B>Success!</B>

<P>You sent: <? echo "$our_file_name"; ?>, a <? echo "$our_file_size"; ?>
byte file with a mime type of <? echo "$our_file_type"; ?>.</p>

</font></body>
</html>