The term upload means moving file from one computer to
another computer .But when we takes it in consideration with php all is that a
file is being moved from one location to another location.
Following easy Steps will upload the file easily....
Checking whether the
server supports uploads-:This first check you must done before you start
coding for the uploading files using php
.For checking this you just need phpinfo()
on your server .Find file_uploads in the
core section ,if it is already on then we are ready to go.
Php configuration settings hat effects the file
uploads-:
Directive Default
value Description
Max_execution_time() 30 This is the maximum no of
seconds for
which a script
can run. If takes longer then it generates fatal error
max _input_time() 60 The maximum no o seconds a
php scripts ys
allowed to pars $_Post and $_get
array.
Post_max_size 8MB The maximum permitted size of
all Post
data.
Upload_temp_dir() This
is the file where php stores temporary files unless it is moved to other place.
Upload_max_file_size 2MB The maximum permitted file size
to upload is 2MB
Adding upload file field using HTML-: It is very easy to
create a upload file interface.
<pre>
<form action=”” method=”post/get” enctype=”multipart/form-data”
id=”imageupload”>
<lable for =”image”>Image upload</lable>
<input type=”file” name=”image” id=”image” >
<input type=”submit” name=”upload” id=”upload” value=”upload”
>
</form>
Use following Simple
file upload code in the action file:-
<?php
if
(isset($_POST['upload']))//check whether the post array is set or not.
{
// define the path
to the upload folder
$destination =
'/path/to/upload_test/';
// move the file
to the upload folder and rename it
move_uploaded_file($_FILES['image']['tmp_name'],
$destination.
$
FILES['image']['name']);
}
?>
<pre>
This
is the simplest and easiest code for uploading
a file using php. A lot more functionality can be added to this code such
as increasing the max file size by MAX_FILE_SIZE.and also can be checked for
the only permitted types of file uploads by simple conditional statement.
No comments:
Post a Comment