With PHP, you may already know, it is possible to upload files on the server with PHP. This lesson will show you in detail how this can happen.
Initially you will need an HTML form for selecting a file such as the example:
![]() |
||||||||||||||||
|
|
Upload Files with PHP
With PHP, you may already know, it is possible to upload files on the server with PHP. This lesson will show you in detail how this can happen.
Initially you will need an HTML form for selecting a file such as the example:
<html>
Note:
- Property with a value of enctype "multipart / form-data" should be added to the tag <form>, when we transfer what binary code files. - Property with a value of type "file" has a browser that field will contain the path to a file and automatically adds button Browse. Important: To allow users to upload files to the server holds enormous risks.For this you have to restrict users that can do this or check whether the file type is before being uploaded to the server. Taking file information Information to a file stored in the global array $ _FILE. Here is example to better understand how it works:
<? php
The first parameter is the name of the array of tag <input>, while the second may be a "name", "type", "size", "tmp_name" or "error" as follows:
$_FILES["File"]["name"] - name of file uploads $_FILES["File"]["type"] - contains the type of file uploads $_FILES["File"]["size"] - contains the size of file uploads $_FILES["File"]["tmp_name"] - name of the temporary file stored on the server $_FILES["File"]["error"] - error (if any) is obtained by uploading a file This is a very easy way of making information about uploaded files, and therefore for greater security is better to restrict the possible formats for uploading to a few. Restrictions on upload Like I said above you should restrict file formats to a few in the following code as the user can upload only gif, png and jpeg images to 80kb:
<?php
Save the uploaded file
The following code containing the above two source codes plus saving of the file. This code also checking if the file already exists on the server and if it does not upload it.
<?php
Next Tutorials
Post Comment |
Need a specific tutorial? Do not hesitate and submit a request! |
||||||||||||||
|
Home | Sitemap |
Terms & Privacy
© ONLINEHOWTO.net 2006-2010 |
||||||||||||||||